Reputation: 337
how to extract RTTI info about methods in Delphi records? is it possible by using new Rtti unit?
Upvotes: 5
Views: 1089
Reputation: 42142
There is no RTTI for methods on records, sorry.
Update: As of Delphi XE2 this is now possible, see online help: https://docwiki.embarcadero.com/CodeExamples/en/TRttiRecordType_(Delphi)
program Program1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Rtti;
type
TKey = record
private
FData: array[0..15] of Byte;
public
function GetByte(Index: Integer): Byte;
// ...
end;
function TKey.GetByte(Index: Integer): Byte;
begin
// ...
end;
var
LContext: TRttiContext;
LType: TRttiType;
LRecord: TRttiRecordType;
LMethod: TRttiMethod;
begin
LContext := TRttiContext.Create;
LType := LContext.GetType(TypeInfo(TKey));
if LType.IsRecord then
begin
LRecord := LType.AsRecord;
{ List all TKey methods }
for LMethod in LRecord.GetMethods do
begin
Writeln(LMethod.ToString);
end;
end;
LContext.Free;
end.
Upvotes: 3