mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 06:28:55 +02:00

the IInterface implementation to be XPCom-compatible --- Merging r15997 through r16179 into '.': U rtl/inc/variants.pp U rtl/inc/objpash.inc U rtl/inc/objpas.inc U rtl/objpas/classes/persist.inc U rtl/objpas/classes/compon.inc U rtl/objpas/classes/classesh.inc A tests/test/tconstref1.pp A tests/test/tconstref2.pp A tests/test/tconstref3.pp U tests/test/tinterface4.pp A tests/test/tconstref4.pp U tests/webtbs/tw10897.pp U tests/webtbs/tw4086.pp U tests/webtbs/tw15363.pp U tests/webtbs/tw2177.pp U tests/webtbs/tw16592.pp U tests/tbs/tb0546.pp U compiler/sparc/cpupara.pas U compiler/i386/cpupara.pas U compiler/pdecsub.pas U compiler/symdef.pas U compiler/powerpc/cpupara.pas U compiler/avr/cpupara.pas U compiler/browcol.pas U compiler/defcmp.pas U compiler/powerpc64/cpupara.pas U compiler/ncgrtti.pas U compiler/x86_64/cpupara.pas U compiler/opttail.pas U compiler/htypechk.pas U compiler/tokens.pas U compiler/objcutil.pas U compiler/ncal.pas U compiler/symtable.pas U compiler/symsym.pas U compiler/m68k/cpupara.pas U compiler/regvars.pas U compiler/arm/cpupara.pas U compiler/symconst.pas U compiler/mips/cpupara.pas U compiler/paramgr.pas U compiler/psub.pas U compiler/pdecvar.pas U compiler/dbgstabs.pas U compiler/options.pas U packages/fcl-fpcunit/src/testutils.pp git-svn-id: trunk@16180 -
89 lines
2.0 KiB
ObjectPascal
89 lines
2.0 KiB
ObjectPascal
{$mode delphi}
|
|
uses
|
|
Classes, SysUtils;
|
|
|
|
type
|
|
ITest = interface ['{AAAA09DA-4019-4A5C-A450-3631A73CF288}']
|
|
function TestIt: integer;
|
|
end;
|
|
|
|
TTestBE = class (TObject, ITest)
|
|
function TestIt: integer;
|
|
{ IInterface }
|
|
function _AddRef: Integer; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
function _Release: Integer; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
function QueryInterface(constref IID: TGUID; out Obj): HResult; virtual; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
End;
|
|
|
|
TTest = class (TPersistent, IInterface)
|
|
BE : TTestBE;
|
|
protected
|
|
{ IInterface }
|
|
function _AddRef: Integer; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
function _Release: Integer; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
function QueryInterface(constref IID: TGUID; out Obj): HResult; virtual; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
|
|
End;
|
|
|
|
function TTestBE.TestIt : integer;
|
|
Begin
|
|
result := 1;
|
|
End;
|
|
|
|
function TTest._AddRef: Integer;
|
|
begin
|
|
Result := -1;
|
|
end;
|
|
|
|
function TTest._Release: Integer;
|
|
begin
|
|
Result := -1;
|
|
end;
|
|
|
|
function TTest.QueryInterface(constref IID: TGUID; out Obj): HResult;
|
|
begin
|
|
Result := BE.QueryInterface(IID, obj);
|
|
end;
|
|
|
|
function TTestBE._AddRef: Integer;
|
|
begin
|
|
Result := -1;
|
|
end;
|
|
|
|
function TTestBE._Release: Integer;
|
|
begin
|
|
Result := -1;
|
|
end;
|
|
|
|
function TTestBE.QueryInterface(constref IID: TGUID; out Obj): HResult;
|
|
begin
|
|
if GetInterface(IID, Obj)
|
|
then Result := 0
|
|
end;
|
|
|
|
|
|
|
|
|
|
Var
|
|
Test : TTest;
|
|
A : ITest;
|
|
begin
|
|
Test := TTest.Create;
|
|
Test.BE := TTestBE.Create;
|
|
|
|
// Works ok in Lazarus and Delphi
|
|
Test.BE.GetInterface (ITest, A);
|
|
// Works ok in Lazarus. Delphi will not compile this line
|
|
A := Test.BE As ITest;
|
|
|
|
// Both Delphi and Lazarus return nil ptr
|
|
Test.GetInterface(ITest, A);
|
|
|
|
// Works in Lazarus
|
|
Test.QueryInterface (ITest, A);
|
|
|
|
// Lazarus throws typecast error.
|
|
// Works fine in delphi because delphi calls QueryInterface while Lazarus does not
|
|
A := Test As ITest;
|
|
end.
|
|
|