вот так будет работать:
Код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TypInfo;
type
{ $M +}
TMyType = class
private
FCaption: String ;
published
property Caption: String read FCaption write FCaption;
end ;
{ $M -}
TForm1 = class (TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end ;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1 . Button1Click(Sender: TObject);
var
X: TMyType;
begin
SetStrProp(Sender, 'Caption' , 'Test' );
ShowMessage( 'Wow' );
X := TMyType . Create;
try
SetStrProp(X, 'Caption' , 'Test' );
ShowMessage(X . Caption);
finally
FreeAndNil(X);
end ;
end ;
end .
|
+ для информации:
The $M switch directive controls
generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section. If a class is declared in the {$M-} state, and is not derived from a class that was declared in the {$M+} state, published sections are not allowed in the class. Note that if a class is forward declared, the first declaration of the class must be declared with the $M switch.