callcli.pas

来自「这是一个网络数据库回调例程,基于SocketConnection的」· PAS 代码 · 共 81 行

PAS
81
字号
{Program to demonstrate callbacks between server and client over SocketServer.
This uses the new capabilities in D4.

Written by Dan Miser
Copyright 1998}
unit CallCli;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBClient, MConnect, StdCtrls, CallbackSrv_TLB, SConnect, ComObj, ActiveX,
  DB;

type
  TClient = class(TAutoIntfObject, IClient)
  protected
    procedure Progress(RecNo, RecCount: integer; var Continue: WordBool); safecall;
    procedure Done; safecall;
  end;

  TfrmClient = class(TForm)
    btnTraverse: TButton;
    DCOMConnection1: TDCOMConnection;
    SocketConnection1: TSocketConnection;
    chkStop: TCheckBox;
    gbProgress: TGroupBox;
    lblProgress: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    procedure btnTraverseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FClient: TClient;
  public
    { Public declarations }
    MyDispatchConnection: TDispatchConnection;
  end;

var
  frmClient: TfrmClient;

implementation

{$R *.DFM}

procedure TClient.Progress(RecNo, RecCount: integer; var Continue: WordBool);
begin
  frmClient.lblProgress.Caption:=Format('%d/%d', [RecNo, RecCount]);
  Application.ProcessMessages;
  Continue:=not frmClient.chkStop.Checked;
end;

procedure TClient.Done;
begin
  ShowMessage('Done!! [callback]');
end;


procedure TfrmClient.btnTraverseClick(Sender: TObject);
begin
  MyDispatchConnection.AppServer.TraverseTable;
end;

{MyDispatchConnection shows how to switch between multiple DipatchConnection}
{components easily, using polymorphism.}
procedure TfrmClient.FormCreate(Sender: TObject);
var
  typelib: ITypeLib;
begin
  MyDispatchConnection:=SocketConnection1;
  MyDispatchConnection.Connected:=true;
  OleCheck(LoadRegTypeLib(LIBID_CallbackSrv, 1, 0, 0, typelib));
  FClient:=TClient.Create(typelib, IClient);

  MyDispatchConnection.AppServer.SetCallback(FClient as IDispatch);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?