SIGSEGV exception when freeing

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

SIGSEGV exception when freeing

Post by binfch » Wed 17 Apr 2013 07:20

Hi there

I am having an issue in a destructor to free some components. Below a test prg. I am using Lazarus 1.0.6 on Linux and PgDac 3.6.12

P.S: With 'DisconnectMode := False' it seems to work fine!

Code: Select all

program project1;

{$mode objfpc}{$H+}

uses
  BaseUnix,
  cthreads,
  cMem,
  Classes,
  SysUtils,
  Interfaces,
  Forms,
  Unit1,
  Unit2;

{$R *.res}

begin
  RequireDerivedFormResource := True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Code: Select all

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit2;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    lDemoClass: TDemoClass;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  lDemoClass := TDemoClass.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  lDemoClass.Free;
end;

end.

Code: Select all

unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  Dialogs,

  //Devart
  DB,
  DBAccess,
  PgAccess,
  PgAlerter,
  MemData;

type
  TDemoClass = class(TObject)
  private
    lPgAlerter: TPgAlerter;
    lPgConnection: TPgConnection;
    procedure AlerterEvent(Sender: TObject; const EventName: AnsiString; PID: LongInt; const EventMessage: AnsiString);
  public
    constructor Create; virtual;
    destructor Destroy; override;
  end;

implementation

procedure TDemoClass.AlerterEvent(Sender: TObject; const EventName: AnsiString; PID: LongInt; const EventMessage: AnsiString);
begin
end;

constructor TDemoClass.Create;
begin
  inherited;

  lPgConnection := TPgConnection.Create(nil);
  with lPgConnection do begin
    Options.DisconnectedMode := True;

    Server := '.....';
    Port := 5432;
    Database := '.....';
    Schema := '.....';
    Username := '.....';
    Password := '.....';
  end;

  lPgAlerter := TPgAlerter.Create(nil);
  with lPgAlerter do begin
    OnEvent := @AlerterEvent;
    AutoRegister := False;
    Connection := lPgConnection;
    Events := 'Test123';
    Start;
  end;

ShowMessage('OK-All Created');
end;

destructor TDemoClass.Destroy;
begin
ShowMessage('Start Freeing');

  lPgAlerter.Stop;
  lPgConnection.Close;
ShowMessage('OK-Disconnected');

  lPgAlerter.Free;
  lPgConnection.Free;
ShowMessage('OK-Destroyed');

  inherited;
end;

end.
Thx & cheers,
Peter

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: SIGSEGV exception when freeing

Post by AlexP » Wed 17 Apr 2013 13:38

Hello,

DisconnectedMode is designed to minimize traffic and decrease the number of contacts to server, as well as for work in unstable networks, in which disconnections occur. In this mode, connection is established only when necessary (retrieve/send data to server), therefore this mode cannot be used with TPgAlerter, since TPgAlerter requires permanent connection to DB.

Post Reply