⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createcomplexprops.txt

📁 FlexGraphics是一套创建矢量图形的VCL组件
💻 TXT
字号:
Creating Complex Property

First of all, you will need to create your own class, which will extend TCustomProp:

  TMyComplexProp = class(TCustomProp)
  end;

We are going to follow this plan to develop the class:
1. Set flex-property type.
2. Define published properties that are to be contained in property.
3. Create fields/methods for reading/writing to these published properties.
4. Define methods determining default values of published properties. 
5. Method for determination of published property type.
6. Read/write data to non-standard published properties.
7. Display flex-property data in inspector.
8. Create form for editing complex flex-property in FlexEdit.

Let's get to business.

1. Since we are going to create a complex flex-property, we will need to specify its type in the constructor right off:

  TMyComplexProp = class(TCustomProp)
  public
   constructor Create(AOwner: TPropList; const AName: string);
  end;

constructor TMyComplexProp.Create(AOwner: TPropList; const AName: string);
begin
 inherited;
 FPropType := ptComplex;
end;

2. Defining published properties to be contained in the property.

Suppose, we need to save some integer value, name, and data, stored in a different object, in the property (provided the object is to be created in our flex-property). Then this is the description we are going to have:

  TMyComplexProp = class(TCustomProp)
  private
   FValue: integer;
   FCaption: string;
   FData: TMyData;
   procedure SetCaption(const Value: string);
   procedure SetData(const Value: TMyData);
   procedure SetValue(const Value: integer);
  public
   . . .
  published
   property  Value: integer read FValue write SetValue;
   property  Caption: string read FCaption write SetCaption;
   property  Data: TMyData read FData write SetData;
  end;

Now, let TMyData is a child of TPersistent (which allows addressing to the Assign method):

  TMyData = class(TPersistent)
  public
    procedure Assign(Source: TPersistent); override;
  end;

Also, let it contain methods that allow reading/writing TMtData's data to TStream streams:

  TMyData = class(TPersistent)
  public
    . . .
    procedure SaveToStream(AStream: TStream);
    procedure LoadFromStream(AStream: TStream);
  end;
  
These methods will make the procedure of reading/writing data to fxd documents simpler. The internal implementation of these methods will be unimportant for the implementation of TMyComplexProp.

3. Creating fields/methods for reading/writing to these published properties.

The architecture of flex-properties is made in such way that any change of data in a flex-property leads to notification of owner of the flex-property 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -