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!
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
TBitmap32member, override thePaint()method to draw the bitmap at both run-time and design-time, and then respond to theCM_DESIGNHITTESTmessage so that your component can react to mouse activity at design-time while the mouse is over the bitmap. You can then override the standardMouseDown/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’sComponentStateproperty for thecsDesigningflag).To save the bitmap to the DFM, you can either expose the
TBitmap32as a published property (which offers an alternative way of manipulating the bitmap at design-time), or override your component’sDefineProperties()method to stream the bitmap manually.