通过INI文件实现HYDRA各插件间对象共享

type TLoginUser = record //登陆用户结构

   id: string;

   name: string;

   ruleid: string;

   rulename: string;

   pwd: string;

end;

 

PShareObjectRecord = ^TShareObjectRecord;

TShareObjectRecord = record //共享对象结构

   Connection: TADOConnection;

   LoginUser: TLoginUser;

end;

 

var

   G_PShareObjectRecord: PShareObjectRecord;//全局共享对象指针

 

system.ini //ini文件保存共享结构的指针值

 [pointer]

shareobj=13609472

 

//把共享的对象指针传入全局共享结构内

 G_PShareObjectRecord^.Connection := ADOConnection1;

with G_PShareObjectRecord.LoginUser do //记录登录用户资料

begin

id := FindField('id').AsString; name := FindField('name').AsString;

 ruleid := FindField('ruleid').AsString;

 rulename := FindField('rulename').AsString;

 pwd := FindField('pwd').AsString;

end;

 

 procedure THostForm.FormShow(Sender: TObject);//保存全局共享对象结构的指针

var ini: TIniFile;

path: string;

begin

path := ExtractFilePath(Application.ExeName) + 'system.ini';

ini := TIniFile.Create(path);

 ini.WriteInteger('pointer', 'shareobj', THandle(G_PShareObjectRecord));

 ini.Free;

end;

 

//取共享对象

 function GetConnection: TADOConnection;

var

 ini: TIniFile;

path: string;

p: Integer;

begin

path := ExtractFilePath(Application.ExeName) + 'system.ini';

ini := TIniFile.Create(path);

 p := ini.ReadInteger('pointer', 'shareobj', 0);

Result := PShareObjectRecord(THandle(p))^.Connection;

 ini.Free;

end;

 

 function GetLoginUser: TLoginUser;

var

 ini: TIniFile;

 path: string;

p: Integer;

 begin

path := ExtractFilePath(Application.ExeName) + 'system.ini';

ini := TIniFile.Create(path);

 p := ini.ReadInteger('pointer', 'shareobj', 0);

Result := PShareObjectRecord(THandle(p))^.LoginUser;

ini.Free;

end;

posted @ 2010-12-05 22:06  delphi中间件  阅读(403)  评论(0编辑  收藏  举报