Through the trtticontext (record) of the rtti unit, you can conveniently obtain the list of methods, attributes, and fields of the class.
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls;
Type
Tform1 = Class (tform)
Memo1: tmemo;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure button5click (Sender: tobject );
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Uses rtti;
// Trtticontext. gettypes
Procedure tform1.button1click (Sender: tobject );
VaR
CTX: trtticontext;
T: trttitype;
Begin
Memo1.clear;
For T in CTX. gettypes do memo1.lines. Add (T. Name );
End;
// Obtain the tbutton Class Method
Procedure tform1.button2click (Sender: tobject );
VaR
CTX: trtticontext;
T: trttitype;
M: trttimethod;
Begin
Memo1.clear;
T: = CTX. GetType (tbutton );
// For m in T. getmethods do memo1.lines. Add (M. Name );
For m in T. getmethods do memo1.lines. Add (M. tostring );
End;
// Obtain attributes of the tbutton class
Procedure tform1.button3click (Sender: tobject );
VaR
CTX: trtticontext;
T: trttitype;
P: trttiproperty;
Begin
Memo1.clear;
T: = CTX. GetType (tbutton );
// For P in T. getproperties do memo1.lines. Add (P. Name );
For P in T. getproperties do memo1.lines. Add (P. tostring );
End;
// Obtain fields of the tbutton class
Procedure tform1.button4click (Sender: tobject );
VaR
CTX: trtticontext;
T: trttitype;
F: trttifield;
Begin
Memo1.clear;
T: = CTX. GetType (tbutton );
// For F in T. getfields do memo1.lines. Add (F. Name );
For f in T. getfields do memo1.lines. Add (F. tostring );
End;
// Obtain the method set, attribute set, and field set for the tbutton class.
Procedure tform1.button5click (Sender: tobject );
VaR
CTX: trtticontext;
T: trttitype;
MS: tarray <trttimethod>;
PS: tarray <trttiproperty>;
FS: tarray <trttifield>;
Begin
Memo1.clear;
T: = CTX. GetType (tbutton );
MS: = T. getmethods;
PS: = T. getproperties;
FS: = T. getfields;
Memo1.lines. Add (format ('% S Class Total % d methods', [T. Name, length (MS)]);
Memo1.lines. Add (format ('% s class has % d attributes in total', [T. Name, length (PS)]);
Memo1.lines. Add (format ('% S Class Total % d fields', [T. Name, length (FS)]);
End;
End.