legacy code - What's the equivalent in Delphi 3 of Supports for Interfaces? -
i support application written in delphi 3 , put in improvements source code while waiting opportunity upgrade newer version of delphi. 1 of things use interfaces. know delphi 3 has concept of interfaces having trouble finding out how equivalent of
if supports(objectinstance, imyinterface)
write own implementation of "supports" function. in delphi 2009 can use
function mysupports(const instance: tobject; const iid: tguid): boolean; var temp: iinterface; lunknown: iunknown; begin result:= (instance <> nil) , ((instance.getinterface(iunknown, lunknown) , (lunknown.queryinterface(iid, temp) = 0)) or instance.getinterface(iid, temp)); end;
test:
procedure tform4.button3click(sender: tobject); var obj: tinterfacedobject; begin obj:= tinterfacedobject.create; if mysupports(obj, iunknown) showmessage('!!'); end;
hope work in delphi 3
Comments
Post a Comment