小弟 初学三层 dcomconnection1.AppServer.方法 这个方法怎么在中间层声明呀(100分)

  • 主题发起人 主题发起人 daviddu
  • 开始时间 开始时间
D

daviddu

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟 初学三层 dcomconnection1.AppServer.方法 这个方法怎么在中间层声明呀?
最好给出代码
 
只要在Type Library中定义接口方法就行了,很简单,用了就知道了![:D]
不要忘记给我点分啊
 
to:Clearboy
怎么定义呀? 给点代码
 
用VIEW->TYPE library
在窗囗中按FUNCTION,加入方法后改名加參數(可選)
sample:
unit srvrdm;
{
This is the server side of the demo. A Login procedure has been added to the
RemoteDataModule which the client will use to login. You can use the Type
Library Editor or the Edit | Add To Interface menu to add a procedure to the
type library.
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComServ, ComObj, VCLCom, StdVcl, DataBkr, DBClient, server_tlb,
Db, DBTables, Provider, Variants;
type
TLoginDemo = class(TRemoteDataModule, ILoginDemo)
Country: TTable;
CountryProvider: TDataSetProvider;
CountryName: TStringField;
CountryCapital: TStringField;
CountryContinent: TStringField;
CountryArea: TFloatField;
CountryPopulation: TFloatField;
procedure LoginDemoCreate(Sender: TObject);
procedure LoginDemoDestroy(Sender: TObject);
procedure CountryProviderBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
private
FLoggedIn: Boolean;
FUserName: string;
procedure CheckLogin;
protected
procedure Login(const UserName, Password: WideString);
safecall;
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
procedure ra;
safecall;
procedure addlist(const time: WideString);
safecall;
procedure openserver;
safecall;
procedure apply(var ds: OleVariant);
safecall;
end;

var
LoginDemo: TLoginDemo;
implementation
uses SrvrFrm;
{$R *.dfm}
{ This procedure is a helper to check that someone has actually logged into the
server. }
procedure TLoginDemo.CheckLogin;
begin
if not FLoggedIn then
raise Exception.Create('Not logged in');
end;

procedure TLoginDemo.Login(const UserName, Password: WideString);
begin
{ Just add the UserName to the ListBox on Form1 and set the login flag to
true.}
Form1.ListBox1.Items.Add(UserName);
FLoggedIn := True;
FUserName := UserName;
end;

procedure TLoginDemo.LoginDemoCreate(Sender: TObject);
begin
FLoggedIn := False;
end;

procedure TLoginDemo.LoginDemoDestroy(Sender: TObject);
begin
{ Remove the Name from the list}
with Form1.ListBox1.Itemsdo
Delete(IndexOf(FUserName));
end;

class procedure TLoginDemo.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 TLoginDemo.ra;
begin
raise exception.Create('Only Raise Error!');
end;

procedure TLoginDemo.addlist(const time: WideString);
begin
form1.ListBox1.Items.Add(time);
end;

procedure TLoginDemo.openserver;
begin
country.Close;
//raise exception.Create('test for producre name !');
end;

procedure TLoginDemo.CountryProviderBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
begin
if deltads.FieldByName('area').AsFloat<=0 then
begin
applied:=true;
raise exception.Create('area less than 0!');
end;
end;

procedure TLoginDemo.apply(var ds: OleVariant);
var
ierror:integer;
begin
country.Database.StartTransaction;
try
if not varisnull(ds) then
begin
ds:=countryprovider.ApplyUpdates(ds,0,ierror);
if ierror>0 then
sysutils.Abort;
end;
country.Database.Commit;
except
country.Database.Rollback;
end;

end;

initialization
TComponentFactory.Create(ComServer, TLoginDemo,
Class_LoginDemo, ciMultiInstance, tmSingle);
end.
 
打开Type Libray(类型库)定义窗口,在接口里加入自己的方法或者属性,然后在dm里实现它,客户端就可以类似
AppServer.方法
AppServer.属性 := 值;
 

Similar threads

回复
0
查看
804
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部