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

📄 createcontrols.txt

📁 FlexGraphics是一套创建矢量图形的VCL组件
💻 TXT
字号:
Developing vector flex-object for isosceles triangle

Any new class of flex-objects must extend TFlexControl or one of its children. Since we do not have an existing class that
we could extend, like, for instance, TFlexText extends TFlexBox, we are going to use the abstract TFlexControl class as
parent.
In general, we could have also used TFlexCurve as parent, but in that case we would have to cut the functionality of that
object too much (changing quantity and positions of points, etc. is not allowed.)

Let抯 name our class TFlexTriangle:

type
  TFlexTriangle = class(TFlexControl)
  end;

We are going to follow this plan to develop the class: 
1. Define object properties
2. Initialize object
3. Property change event parser
4. Property default value flag parser
5. Draw object
6. Obtain the update rectangle
7. Check whether the point belongs to the object
8. Translate object
9. Obtain points of merging with interconnection lines
10. Convert object to curves
11. Object抯 anchor point
12. Pass data on object to editor
13. Register object

After number 5 we can already create an instance of the object in the pane and check out the result. At the same time, when
moving the object, especially using large scale, the object will leave traces of garbage. Completing number 6 will fix that.
Basically, all other steps are optional and must be completed only when the behavior of object must be different what is set
as default (what, honestly, happens quite frequently.)

Number 7 clarifies object抯 boundaries when checking whether the point belongs to the object. By default, object is
accepted as rectangle and matching its dimensions, Width and Height.

Number 8 is implemented when object抯 appearance is to be changed when the object is rotated and/or mirrored.

Number 9 is executed only when flexible interconnection lines TFlexConnector can be connected to object.

Number 10 makes sense only for vector objects when the conversion of objects to curves is required.

Number 11 is executed if object抯 anchor point must not be in the object抯 upper-left corner.

Number 12 is implemented if the object is going to be used in FlexEdit.

Number 13 is implemented if object can be read from or written to streams.

However, other steps may have to be taken for the implementation of particular functionality (to implement the support of
points on object, one must override methods dealing with them: GetPoint, SetPoint, DeletePoint, etc.)
For the description of basic virtual methods of TFlexControl, please refer to the help file.

1. Defining object properties

The number and types of properties depend on methods to be used for drawing object and data the object is to store. For
instance, to draw a rectangle, we will need border style and shading style; however, these properties do not make any sense
for a raster image.

In our case, just like with the rectangle, we will need border style and shading styles. To ensure the compatibility of
property names in different applications, there is a common rule for naming property after the name of its class:
for the class TBrushProp - "Brush", for the class TPenProp - "Pen",
TPictureProp - "Picture", and so on. This rule is followed to ensure the universal access to properties by their names,
regardless to object抯 class.
For example, here is the way how we can access shading style of any object:

 Brush: TBrupProp;
 Control: TFlexControl;
 begin
  . . .
  Brush := TBrushProp(Control.Props['Brush']);
  if Assigned(Brush) then begin
   . . .
  end;
  . . .
 end;

If there is no property with the required name in the object (e.g., "Brush"
for TPictureProp), the request of Control.Props['Brush'] will simply return Nil.

So, let抯 follow this rule and set two style properties, for border and shading:

  private
   FBrushProp: TBrushProp;
   FPenProp: TPenProp;

Now, since the library抯 methods can rotate objects by 90-degree divisible angles, we need to know the 揹irection

⌨️ 快捷键说明

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