Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: FireDAC EventAlerter problem


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Dec 10, 2015 12:09 AM Last Post By: Jan-Erich Schir...
Jan-Erich Schir...

Posts: 6
Registered: 3/1/02
FireDAC EventAlerter problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 4, 2015 12:25 AM
Hi,
Iam using XE10 and FireDAC, Windows 32Bit-Application developed with Windows 7, Windows 64.

Problem using PostgreSQL with an FDEventAlerter: The program works, but when destroying the FD-Components FireDAC sometimes raises an exception or simply hangs with the SQL-Cursor.

The example program is a Form with a button. When I press the button a connection is created and an alerter. When I it press again the components are destroyed. See the simple code below

Any Idea? Has it to do with asynchronous background processing? I tried Option.Synchronize but seems not to be a difference.

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
Data.DB, FireDAC.Comp.Client, Vcl.StdCtrls, FireDAC.Phys.PG;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OnAlert(ASender: TFDCustomEventAlerter; const AEventName: String; const AArgument: Variant);
public
Connection: TFDConnection;
EventAlerter: TFDEventAlerter;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Connection) then begin
Connection := TFDConnection.Create(nil);
Connection.DriverName := 'PG';
Connection.Params.Add('Server=192.168.67.153');
Connection.Params.Add('User_Name=admin');
Connection.Params.Add('Database=mydb');
Connection.Params.Add('Password=mypassword');
Connection.Connected := true;

EventAlerter := TFDEventAlerter.Create(nil);
EventAlerter.Connection := Connection;
EventAlerter.Names.Add('Willi');
EventAlerter.OnAlert := OnAlert;
EventAlerter.Options.Synchronize := true;
EventAlerter.Active := true;

Caption := 'Connected';

end else begin
FreeAndNil(EventAlerter);
FreeAndNil(Connection);
Caption := 'Disconnected';
end;
end;

procedure TForm1.OnAlert(ASender: TFDCustomEventAlerter;
const AEventName: String; const AArgument: Variant);
begin
Caption := 'Event '+AEventName;
end;

end.

Edited by: Jan-Erich Schirrmacher on Dec 4, 2015 12:26 AM

Jan-Erich Schir...

Posts: 6
Registered: 3/1/02
Re: FireDAC EventAlerter problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2015 12:09 AM   in response to: Jan-Erich Schir... in response to: Jan-Erich Schir...
Problem solved using DevArts PgDAC. Easier to use, faster, more robust.

Jan-Erich Schirrmacher wrote:
Hi,
Iam using XE10 and FireDAC, Windows 32Bit-Application developed with Windows 7, Windows 64.

Problem using PostgreSQL with an FDEventAlerter: The program works, but when destroying the FD-Components FireDAC sometimes raises an exception or simply hangs with the SQL-Cursor.

The example program is a Form with a button. When I press the button a connection is created and an alerter. When I it press again the components are destroyed. See the simple code below

Any Idea? Has it to do with asynchronous background processing? I tried Option.Synchronize but seems not to be a difference.

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
Data.DB, FireDAC.Comp.Client, Vcl.StdCtrls, FireDAC.Phys.PG;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OnAlert(ASender: TFDCustomEventAlerter; const AEventName: String; const AArgument: Variant);
public
Connection: TFDConnection;
EventAlerter: TFDEventAlerter;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Connection) then begin
Connection := TFDConnection.Create(nil);
Connection.DriverName := 'PG';
Connection.Params.Add('Server=192.168.67.153');
Connection.Params.Add('User_Name=admin');
Connection.Params.Add('Database=mydb');
Connection.Params.Add('Password=mypassword');
Connection.Connected := true;

EventAlerter := TFDEventAlerter.Create(nil);
EventAlerter.Connection := Connection;
EventAlerter.Names.Add('Willi');
EventAlerter.OnAlert := OnAlert;
EventAlerter.Options.Synchronize := true;
EventAlerter.Active := true;

Caption := 'Connected';

end else begin
FreeAndNil(EventAlerter);
FreeAndNil(Connection);
Caption := 'Disconnected';
end;
end;

procedure TForm1.OnAlert(ASender: TFDCustomEventAlerter;
const AEventName: String; const AArgument: Variant);
begin
Caption := 'Event '+AEventName;
end;

end.

Edited by: Jan-Erich Schirrmacher on Dec 4, 2015 12:26 AM

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02