可以更进一步,随便你要发多少信息都可以设置的.
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, Provider, DB, DBTables;
type
TDcom = class(TRemoteDataModule, IDcom)
Database1: TDatabase;
Query1: TQuery;
DataSetProvider1: TDataSetProvider;
procedure RemoteDataModuleCreate(Sender: TObject);
procedure DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
end;
implementation
uses Unit1;
{$R *.DFM}
class procedure TDcom.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;
procedure TDcom.RemoteDataModuleCreate(Sender: TObject);
begin
with database1do
begin
databasename:='dbdemos';
connected:=true;
end;
with
query1do
begin
databasename:='dbdemos';
close;
sql.clear;
sql.add('select * from animals');
open;
end;
datasetprovider1.dataset:=query1;
end;
procedure TDcom.DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
var s:string;
begin
s:=datetimetostr(now)+':数据已经发送到客户端';
form1.addmessage(s);
end;
procedure TDcom.DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
var s:string;
begin
s:=datetimetostr(now)+':数据准备完成';
form1.addmessage(s);
end;
initialization
TComponentFactory.Create(ComServer, TDcom,
Class_Dcom, ciMultiInstance, tmApartment);
end.