What's the equivalent in Delphi 3 of Supports for Interfaces?

I support an application written in Delphi 3 and I would like to put in some improvements to the source code while waiting for the opportunity to upgrade it to a newer version of Delphi. One of the things I would like to use is Interfaces. I know Delphi 3 already has the concept of Interfaces but I am having trouble finding out how to do the equivalent of

if Supports(ObjectInstance, IMyInterface) then

Answers


Write your own implementation of "Supports" function. In Delphi 2009 you can use

function MySupports(const Instance: TObject; const IID: TGUID): Boolean;
var
  Temp: IInterface;
  LUnknown: IUnknown;
begin
  Result:= (Instance <> nil) and
           ((Instance.GetInterface(IUnknown, LUnknown)
             and (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) then
    ShowMessage('!!');
end;

Hope it will work in Delphi 3


Need Your Help

Google AppEngine development server arguments

eclipse gwt

In the Eclipse Run Configurations for Google Web Applications, I see a list of program arguments, like this:

How do you back up an android app?

java android backup reinstall

I just had my app crash and now after alot of work its back to were I had it, I was wondering how would I back up the app so I can reInstall is again if this ever happens again?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.