I'm trying to list my interfaces and classes to build a framework, but the GetTypes () method doesn't find my types, what do I have to change in my source to make it possible?
unit untPrincipal;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Rtti, Vcl.StdCtrls, System.TypInfo;
type
TForm1 = class(TForm)
btnTeste: TButton;
mmoSaida: TMemo;
procedure btnTesteClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
IMyInterface = interface(IInterface)
['{60B148AA-0750-432F-8AC0-1423707803AC}']
procedure Fazer;
end;
IMyInterface2 = interface(IInvokable)
['{80A5566A-D8A4-44A7-AEC6-7874F95EFA13}']
procedure Fazer;
end;
{$M+}
IMyInterface3 = interface
['{7A6ED55C-2A96-4BCF-ADD1-65159B37F258}']
procedure Fazer;
end;
{$M-}
TMyClass = class(TInterfacedObject, IMyInterface)
public
procedure Fazer;
end;
TMyClass2 = class(TInterfacedObject, IMyInterface2)
public
procedure Fazer;
end;
TMyClass3 = class(TInterfacedObject, IMyInterface3)
public
procedure Fazer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnTesteClick(Sender: TObject);
var
ctx: TRttiContext;
ctypes: TArray<TRttiType>;
ctype: TRttiType;
begin
mmoSaida.Clear;
ctx := TRttiContext.Create;
try
ctypes := ctx.GetTypes();
for ctype in ctypes do
begin
mmoSaida.Lines.Add(ctype.ToString)
end;
finally
ctx.Free;
end;
end;
{ TMyClass }
procedure TMyClass.Fazer;
begin
ShowMessage('procedure TMyClass.Fazer;');
end;
{ TMyClass2 }
procedure TMyClass2.Fazer;
begin
ShowMessage('procedure TMyClass2.Fazer;');
end;
{ TMyClass3 }
procedure TMyClass3.Fazer;
begin
ShowMessage('procedure TMyClass3.Fazer;');
end;
end.
The code above lists several types, including TForm1 and other simple types. but it does not list neither my interfaces nor my classes.
Delphi 10.3 Update 1 (Version 26.0.33219.4899)
Thank you