문제

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
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top