Показать сообщение отдельно
  #2  
Старый 11.01.2009, 15:39
xchrom xchrom вне форума
Начинающий
 
Регистрация: 08.04.2008
Сообщения: 177
Репутация: 15
По умолчанию

вот так будет работать:

Код:
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
    { Private declarations }
  public
    { Public declarations }
  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'); // Ooops
    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.
__________________
правильный вопрос содержит в себе 90% ответа
Ответить с цитированием