运行效果如下
窗体布局
object Form1: TForm1
Left = 0
Top = 0
Caption = #31034#20363'-'#23646#24615#32534#36753#22120
ClientHeight = 243
ClientWidth = 527
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object cxRTTIInspector1: TcxRTTIInspector
Left = 8
Top = 8
Width = 297
Height = 227
InspectedObject = Owner
OptionsView.RowHeaderWidth = 120
OptionsView.ShowReadOnlyProperties = True
TabOrder = 0
Version = 1
end
end
窗体代码
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls,
Vcl.StdCtrls,
Vcl.Forms, Vcl.Dialogs, cxClasses, cxPropertiesStore,
cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles,
cxEdit, dxSkinsCore, dxSkinCoffee, cxInplaceContainer, cxVGrid, cxOI,
Vcl.ExtDlgs;
type
TMyObj = class(TPersistent)
private
FLength: Integer;
FWidth: Integer;
FColor: TColor;
FLines: TStrings;
procedure SetLines(const Value: TStrings);
published
property Length : Integer read FLength write FLength;
property Width : Integer read FWidth write FWidth;
property Color : TColor read FColor write FColor;
property Lines : TStrings read FLines write SetLines;
public
constructor Create();
end;
TForm1 = class(TForm)
cxRTTIInspector1: TcxRTTIInspector;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
obj1 : TMyObj;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
obj1 := TMyObj.Create();
obj1.Length := 10;
cxRTTIInspector1.InspectedObject := obj1;
end;
{ TMyObj }
constructor TMyObj.Create;
begin
inherited;
FLines := TStringList.Create;
end;
procedure TMyObj.SetLines(const Value: TStrings);
begin
FLines.Assign(Value);
end;
end.
未解决的问题
属性的提示如何显示为中文?