好的,虽然我对这个主题也很感兴趣,但这里有一些在快速调查后创建的工作示例:
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ZConnection, ZDbcPostgreSql;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
pgConn: TZConnection;
procedure Button1Click(Sender: TObject);
procedure pgConnAfterConnect(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure PGNotifyProcessor(arg: Pointer; message: PAnsiChar); cdecl;
begin
Form1.Memo1.Lines.Add(message);
end;
{ TForm1 }
procedure TForm1.pgConnAfterConnect(Sender: TObject);
var
pg: IZPostgreSQLConnection;
args: Pointer;
begin
pg := pgConn.DbcConnection as IZPostgreSQLConnection;
pg.GetPlainDriver.SetNoticeProcessor(pg.GetConnectionHandle, @PGNotifyProcessor, args);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
pgConn.ExecuteDirect('select foo(''bar'')');
end;
end.
这个对我有用。
我猜这个例子不准确并且包含一些问题。例如在从外部源调用的过程中使用 LCL 调用。但我希望这足以开始。
测试环境为:FPC 2.6.4、Lazarus 1.5、Postgres 9.3、Linux Mint