delphi graphical component to activex - delphi

I made a graphical component which ancestor has to be TGraphiccontrol because I need to paint to the canvas.
Now I want to convert this component to an activex control but that seems to be only possible when the component is a descendant from TWincontrol.
How do I solve this problem?

It is incorrect that you must only use a TGraphicControl in order to paint. Base your control on TCustomControl instead. This provides you with a canvas which you can use the same way, and is inherited from the TWinControl.

Related

Can FireMonkey frames be created dynamically?

FireMonkey has the option of using frames (not TFrame, which is a specific kind of visual component), which basically are collections of visual components which can be reused.
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Working_with_Frames
However, there is nothing in the documentation about creating instances of frames dynamically, instead of placing them at design time on a TForm. Is there a way to create instances of a frame dynamically? When I try to do this, I get errors when attempting to access the frame in question's properties.
TFrame is a simple TControl, you can create and use it as usual Tcontrol component.
If you would change TFrame to TControl - nothing change because it is same.
var
MyFrame: TFrame;
begin
MyFrame := TFrame.Create(Self);
MyFrame.Parent := Self;
Self is TForm or any other TControl

Delphi tcustomcontrol/twincontrol

Can someone please explain me which control is better to create custom componens? What is the difference between twincontrol and tcustomcontrol?
Thank you in advance
Can someone please explain me which control is better to create custom componens?
That depends on what kind of component you are making and what its requires are.
Is it visual?
If no, use TComponent.
if yes, does it need its own HWND (input focus, window messages, etc)?
If no, use TGraphicControl.
If yes, does it need to custom paint itself?
if yes, use TCustomControl.
if no, use TWinControl.
What is the difference between twincontrol and tcustomcontrol?
TCustomControl is a TWinControl descendant that adds some additional handling for the WM_PAINT message, on top of what TWinControl does. TCustomControl exposes a public Canvas property that you can draw on. During painting, it enables the csCustomPaint flag in the ControlState property, and then calls a virtual Paint() method that your component can override. So the benefit of TCustomControl is that it makes custom painting a little easier to manage. Nothing more.

bring to back doesnt work in c++ builder bcb6

I have a TFrame with some components on it, and among all it I have a TPanel and a TPaintBox such that the PaintBox size is the same as the Panel.
I would like that user will see the Panel and not only the PaintBox.
The problem is that when I right click on the Panel and choose Control->Send to Back, it doesn't work.
Any assumption, or suggestion for solution?
*I am working with Borland C++Builder 6.
TPaintBox is a TGraphicControl descendant. It has no HWND of its own, it simply draws on its Parent when the Parent is painted. As such, a TPanel (which has an HWND of its own) can never appear behind a TPaintBox unless the TPaintBox is a child of the TPanel.

What are there advantages to using Static Text instead of Label in Delphi?

From the docwiki for labels:
You place a label on a form when you need to identify or annotate another component such as an edit box or when you want to include text on a form. The standard label component, TLabel, is a non-windowed control, so it cannot receive focus; when you need a label with a window handle, use TStaticText instead.
What does the statement "when you need a label with a window handle, use TStaticText instead" mean?
At work, we use a TStaticText when we want our UI automation testing tool to 'read' the text of a "label". Most of the interaction is done by Windows API messaging, so a TStaticText will respond to GetWindowText, while a TLabel will not. This is a simplistic overview on how we use TStaticText and a TLabel.
Also, if you're creating forms that need to work with screen readers for visually impaired users, TLabels can't be seen by the software, but TStaticText labels can.
Cut and pasted from Embarcadero
The TStaticText component functions like TLabel, except that it
descends from TWinControl and therefore has a window handle. Use
TStaticText instead of TLabel when the component's accelerator key
must belong to a windowed control—for example, on an ActiveX property
page.
I believe the reason there are these two label controls with almost the same functionality is (pre)historical.
In old versions of Windows (old as Windows 3.x), there was a practical limit of number of handles the whole system could have. So using handle-less label control was good way to save these precious system resources. That's why Borland introduced the TLabel.
TStaticText
TStaticText has a Window Handle and can accept focus whereas TLabel does not have a Window Handle and cannot accept focus
TStaticText allows the user to edit the text displayed whereas TLabel does not allow the user to edit the text displayed
TLabel
TLabel's caption property can be changed programmatically whereas TStaticText's Caption property cannot be changed programmatically
TLabel does not have a ShowAccelChar property whereas TStaticText does have a ShowAccelChar property

Creating custom Hint window

I'm trying to find a way to use my 2nd form as a hint window for a component (for example a TLabel) in my 1st form.
At the moment, I'm exploring the use of THintWindow and HintWindowClass, but it is not possible to directly assign a TForm to HintWindowClass. Some examples I've seen so far use a TBitmap which is then drawn on the THintWindow.Canvas, which is not bad, but I'd still like to use some kind of integrated automatic mechanism.
Another solution that crossed my mind is to manually implement this functionality using OnMouseEnter, OnMouseMove and OnMouseLeave events of the said Tlabel.
If there actually is a way to "assign" a TForm to HintWindowClass, I'd like to ask if anyone can provide a code snippet illustrating this. Thanks.
THintWindow is a descendant of TCustomControl. TForm is not a descendant of either of those classes, so you cannot assign any TForm class to HintWindowClass. Hint windows need to descend from THintWindow. Anything you can put on a form you can also put on a THintWindow. You'll just have to instantiate it manually and assign its Parent property to make it appear.
The closest you can probably get to "visually" designing a hint window is to design a frame. Make your THintWindow descendant create an instance of the frame, and then override ActivateHint (and ActivateHintData, if you need the data) to forward the hint text and desired size to your frame.

Resources