找了老半天,这是SERVER DPR:
program Project1;
uses
SvcMgr,
Unit1 in 'Unit1.pas' {Service1: TService},
Project1_TLB in 'Project1_TLB.pas',
Unit2 in 'Unit2.pas' {MyTest1: TRemoteDataModule} {MyTest1: CoClass};
{$R *.TLB}
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TService1, Service1);
Application.Run;
end.
这是SERVER DATAMODULE:
object MyTest1: TMyTest1
OldCreateOrder = False
Left = 270
Top = 107
Height = 150
Width = 215
object DataSetProvider1: TDataSetProvider
DataSet = Table1
Constraints = True
Left = 136
Top = 28
end
object Table1: TTable
DatabaseName = 'DBDEMOS'
TableName = 'country.db'
Left = 56
Top = 24
end
end
这是客户FORM:
object Form3: TForm3
Left = 270
Top = 107
Width = 473
Height = 309
Caption = 'Form3'
object DBGrid1: TDBGrid
Left = 16
Top = 88
Width = 377
Height = 169
DataSource = DataSource1
TabOrder = 0
end
object Button1: TButton
Left = 172
Top = 28
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider1'
RemoteServer = DCOMConnection1
Left = 68
Top = 28
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 100
Top = 28
end
object DCOMConnection1: TDCOMConnection
ServerGUID = '{E8D6F5E4-055C-46E7-BF94-13EC70FDA1A3}'
ServerName = 'Project1.MyTest1'
Left = 36
Top = 28
end
end
客户PAS:
unit CLUnit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, Grids, DBGrids, StdCtrls;
type
TForm3 = class(TForm)
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DCOMConnection1: TDCOMConnection;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
ClientDataSet1.Open;
end;
end.
注意:服务程序要加执行参数-INSTALL进行安装,然后在NT服务控制面板中启动。
D:>Project1.exe -install (提示安装成功)
否则程序会在十几秒内自动退出(你该不是因为没安装自动退出吧,我看很像耶)。