unit Unit1;
{$mode delphi}
{$interfaces corba}
interface
uses
Classes,
SysUtils,
Forms,
Controls,
Graphics,
Dialogs,
//{ rtti }
//Rtti,
//TypInfo,
Generics.Defaults;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
public
end;
ISomeBaseInterface = interface
['{FAB63768-8D37-412B-9BB9-5454751EC982}']
function TestFunc(): String;
procedure Free();
end;
ISomeInterface = interface(ISomeBaseInterface)
['{FAB63768-8D37-412B-9BB9-5454751EC982}']
property prop1: String;
end;
{ TSomeInterfaceImplementation }
TSomeInterfaceImplementation = class(ISomeBaseInterface)
private
fProp1: String;
public
function TestFunc(): String;
property prop1: String read fProp1 write fProp1;
end;
{ TGeneric }
TGeneric<T> = class
SomeField: T;
destructor Destroy(); override;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TSomeInterfaceImplementation }
function TSomeInterfaceImplementation.TestFunc(): String;
begin
Result := 'ok';
end;
{ TGeneric }
destructor TGeneric<T>.Destroy();
begin
if Assigned(SomeField) then
SomeField.Free;
//FreeAndNil(T(SomeField));
inherited;
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
//Gen: TGeneric<ISomeBaseInterface>;
P: ISomeBaseInterface;
begin
//Gen := TGeneric<ISomeBaseInterface>.Create();
//Gen.SomeField := TSomeInterfaceImplementation.Create;
//Gen.Free;
P := TSomeInterfaceImplementation.Create;
with P as ISomeInterface do // <-------------- With COBRA: Class or Com interface type expected
begin
end;
end;
end.