给个示例你,对比一下看是否有参考价值
SERVER:
unit uIServer;
interface
uses
Windows, Messages, SysUtils,
Classes, ComServ, ComObj,
VCLCom, DataBkr,DBClient,
PIServer_TLB, StdVcl, Db, DBTables, Provider;
type
TIServer = class(TRemoteDataModule, IIServer)
Table1: TTable;
DataSetProvider1: TDataSetProvider;
private
{ Private declarations }
protected
//class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
// function Get_Country: IProvider;
safecall;
procedure login(const User, Password: WideString);
safecall;
procedure Logout(const User: WideString);
safecall;
public
{ Public declarations }
end;
var
server: TIserver ;
implementation
uses fIServer;
{$R *.DFM}
{class procedure TIServer.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;
}
//function TIServer.Get_Country: IProvider;
//begin
// Result:=Table1.Provider;
//end;
procedure TIServer.login(const User, Password: WideString);
begin
form1.listbox1.items.addobject(user,tstringstream.create(password));
end;
procedure TIServer.Logout(const User: WideString);
begin
with Form1.Listbox1do
begin
(Items.Objects[Items.IndexOf(User)]).free;
Items.Delete(Items.IndexOf(User));
end;
end;
initialization
TComponentFactory.Create(ComServer, TIServer,
Class_IServer, ciMultiInstance, tmApartment);
end.
SERVER FORM
unit fIServer;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
ListBox1: TListBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.
CLIENT
LOGIN FORM
unit Unit1;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls;
type
TDlg1 = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
Bevel1: TBevel;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Dlg1: TDlg1;
implementation
{$R *.DFM}
end.
MAIN FORM
unit DataFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBClient, MConnect, Grids, DBGrids, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
DBGrid1: TDBGrid;
DCOMConnection1: TDCOMConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
User: wideString;
FLogin: Boolean;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
flogin:= false;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
password: string;
begin
if not(flogin) then
begin
if Dlg1.showModal=mrok then
begin
flogin:= true;
user:= Dlg1.edit1.text;
password:= Dlg1.edit2.text;
dcomconnection1.AppServer.login(user,password);
end;
end;
clientdataset1.Open;
end;
end.