I have to admit that the following code surprised me. I guess it makes sense, but I wouldn’t have guessed that you can expose private functionality via an interface like this. Interesting.
program DoPrivateStuff;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
ITestInterface = interface
procedure DoThisPrivateThing;
procedure DoThisPublicThing;
end;
TTestClass = class(TInterfacedObject, ITestInterface)
private
procedure DoThisPrivateThing;
public
procedure DoThisPublicThing;
end;
{ TTestClass }
procedure TTestClass.DoThisPublicThing;
begin
Writeln('Doing a public thing');
end;
procedure TTestClass.DoThisPrivateThing;
begin
WriteLn('Doing a private thing');
end;
var
Test: ITestInterface;
begin
try
Test := TTestClass.Create;
Test.DoThisPrivateThing;
Test.DoThisPublicThing;
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.