Z
zhrrqy
Unregistered / Unconfirmed
GUEST, unregistred user!
{我想把下面的Database作成Dll,通过Interface公布}
function DatabaseObj:IInterface;
begin
Result:=TDatabase.SingleTonInstance;
end;
class function TDataBase.GetInstance(Request: Integer): TDataBase;
const
FInstance: TDataBase = nil;
begin
case Request of
0:;
1:
begin
{问题就出在这里,我检查了,在exe中,第二次使用时,FInstance<>nil,而转换成dll是,FInstance一直是nil}
if not assigned(FInstance) then
begin
Finstance := CreateInstance;
end;
end;
2:
begin
Finstance := nil;
end;
else
raise Exception.CreateFmt('%d是GetInstance()中的非法参数', [Request]);
end;
Result := FInstance;
end;
function DatabaseObj:IInterface;
begin
Result:=TDatabase.SingleTonInstance;
end;
class function TDataBase.GetInstance(Request: Integer): TDataBase;
const
FInstance: TDataBase = nil;
begin
case Request of
0:;
1:
begin
{问题就出在这里,我检查了,在exe中,第二次使用时,FInstance<>nil,而转换成dll是,FInstance一直是nil}
if not assigned(FInstance) then
begin
Finstance := CreateInstance;
end;
end;
2:
begin
Finstance := nil;
end;
else
raise Exception.CreateFmt('%d是GetInstance()中的非法参数', [Request]);
end;
Result := FInstance;
end;