fpc/tests/test/tinterface8.pp
Frederic Kehrein 1778fb6fe3 Implementing TImplementedInterface.getcopy to allow copying of interfaced objectcs
It's probably not fully correct(see comment about procdef copy) but
seems good enough ¯\_(ツ)_/¯
2024-11-03 14:08:45 +00:00

53 lines
663 B
ObjectPascal

{ %VERSION=1.1 }
{$ifdef fpc}
{$mode objfpc}
{$endif}
type
ITest = interface(IUnknown)
procedure DoSomething;
end;
TMyClass = class(TInterfacedObject, ITest)
procedure DoSomething;
end;
var
i : longint;
procedure TMyClass.DoSomething;
begin
inc(i);
end;
procedure DoTest(const ATest: ITest);
begin
ATest.DoSomething;
end;
procedure DoTest2(ATest: ITest);
begin
ATest.DoSomething;
end;
type TMyClassCopy = type TMyClass;
var
c: ITest;
begin
i:=0;
c := TMyClassCopy.Create;
DoTest(c);
DoTest2(c);
if i<>2 then
begin
writeln('Problem with passing interfaces as parameters');
halt(1);
end;
end.