1
votes

I want to create a graphical component in Delphi that is editable to some extent inside the designtime editor.

I would like to know

  • What component I should inherit from (for example TWinControl or whatever)
  • How to handle component messages (CM_xxx) to be able to move around my component in the editor
  • If it's possible to use native windows components in the designtime editor, but then switch to other component in runtime.

The reason I want to be able (if even necessary) to switch to other type of component in runtime is because the component I intend to use is TBitmap32 from the Graphics32 library which is many times faster than standard windows graphics, but TBitmap32 is not inherited from TWinControl to begin with.

Maybe if possible, I could maybe do something like using standard VCL in designtime and then just take its properties and apply them to TBitmap32.

Example: In designtime I use a TImage which I can move around, and when I run the application it takes the X and Y values, and the bitmap from TImage and apply them to the TBitmap32 component and draw the TBitmap32 component to wherever it needs to be drawn.

Code could look something like this: TMyBMP= class(TImage) private fResultBMP: TBitmap32; .....

I hope you understand, thank you!

2
not according to delphi.about.com/od/vclusing/a/customvcldev_2.htm "Component Messages (CM_) are generated only by the VCL and are not reflected Windows Messages (WM_)"xaid
thats quite incorrect reference. in X message X denotes destination, not an origin.OnTheFly

2 Answers

3
votes

I would not use different components at design-time and run-time. That will just over-complicate your component design. What you use at run-time should be the same thing you use at design-time.

What I would do is have your component contain a TBitmap32 member, override the Paint() method to draw the bitmap at both run-time and design-time, and then respond to the CM_DESIGNHITTEST message so that your component can react to mouse activity at design-time while the mouse is over the bitmap. You can then override the standard MouseDown/Move/Up() methods to manipulate your bitmap positioning/sizing as needed (inside those methods, you can differentiate between run-time and design-time by checking your component's ComponentState property for the csDesigning flag).

To save the bitmap to the DFM, you can either expose the TBitmap32 as a published property (which offers an alternative way of manipulating the bitmap at design-time), or override your component's DefineProperties() method to stream the bitmap manually.

1
votes

You can create a component inherited from TGraphicControl or TWinControl. The latter is needed if you want your control be able to receive focus and Windows messages. Your component should use TBitmap32 as a buffer - you do all paint there, in memory. In the Paint method (which you override) you copy contents from the buffer to screen using BitBlt or similar function.