The Objauto unit should be considered an extension of the Typinfo unit, right? It provides 5 methods:
GetMethods, Getmethodinfo, Createmethodpointer, Releasemethodpointer, Objectinvoke
The details of the public members of the class can be obtained through GetMethods, Getmethodinfo.
The information (example) of the members in the published area can only be obtained through typinfo;
Member information for the public area can also be obtained through Objauto.
This example effect chart:
This example has two units, and the Auxiliary Unit (UNIT2) holds 3 classes for testing:Unit Unit2;
Interface
Type
TCLASS1 does not specify additional compilation instructions, Objauto can only obtain methods of its published area
TClass1 = Class
function fun1:string;
Private
function fun1private:string;
Protected
function fun1protected:string;
Public
function fun1public:string;
Published
function fun1published:string;
End
TClass2 specified {$M +}, Objauto can get methods for its published and default regions.
In general, the default area's members are equivalent to the public area;
After {$M +} is specified, the member of the default zone is equivalent to the published area.
Since Tpersistent (which is the ancestor of many classes) has already specified {$M +}, most of the classes are {$M +} open.
{$M +}
TClass2 = Class
function fun2:string; {Default Zone}
Private
function fun2private:string;
Protected
function fun2protected:string;
Public
function fun2public:string;
Published
function fun2published:string;
End
{$M-}
The compiler directive Methodinfo is the Delphi 2009 new, only then it opens, Objauto can obtain the public area the information.
This allows Objauto to obtain information about the TCLASS3 's public, published, and default areas.
{$M +}
{$METHODINFO on}
TCLASS3 = Class
function fun3:string;
Private
function fun3private:string;
Protected
function fun3protected:string;
Public
function fun3public:string;
Published
function fun3published:string;
End
{$METHODINFO off}
{$M-}
Implementation
{TClass1-------------------------------------------------}
function TClass1.Fun1:string;
Begin
Result: = ' Fun1 ';
End
function TClass1.Fun1Private:string;
Begin
Result: = ' fun1private ';
End
function TClass1.Fun1Protected:string;
Begin
Result: = ' fun1protected ';
End
function TClass1.Fun1Public:string;
Begin
Result: = ' fun1public ';
End
function TClass1.Fun1Published:string;
Begin
Result: = ' fun1published ';
End
{TClass2-------------------------------------------------}
function TClass2.Fun2:string;
Begin
Result: = ' Fun2 ';
End
function TClass2.Fun2Private:string;
Begin
Result: = ' fun2private ';
End
function TClass2.Fun2Protected:string;
Begin
Result: = ' fun2protected ';
End
function TClass2.Fun2Public:string;
Begin
Result: = ' fun2public ';
End
function TClass2.Fun2Published:string;
Begin
Result: = ' fun2published ';
End
{TCLASS3-------------------------------------------------}
function TClass3.Fun3:string;
Begin
Result: = ' Fun3 ';
End
function TClass3.Fun3Private:string;
Begin
Result: = ' fun3private ';
End
function TClass3.Fun3Protected:string;
Begin
Result: = ' fun3protected ';
End
function TClass3.Fun3Public:string;
Begin
Result: = ' fun3public ';
End
function TClass3.Fun3Published:string;
Begin
Result: = ' fun3published ';
End
End.