In Delphi 10.4, in a VCL Application, using the OnMessage
event-handler of a TApplicationEvents
component, I increase the font-size of the right-clicked Control:
procedure TformMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
ThisControl: TControl;
begin
if (Msg.Message = WM_RBUTTONDOWN) then
begin
ThisControl := FindDragTarget(Mouse.CursorPos, True);
CodeSite.Send('TformMain.ApplicationEvents1Message: RIGHTCLICK!', ThisControl.Name);
if ThisControl is TLabel then
TLabel(ThisControl).Font.Size := TLabel(ThisControl).Font.Size + 1
else if ThisControl is TCheckBox then
TCheckBox(ThisControl).Font.Size := TCheckBox(ThisControl).Font.Size + 1;
// ETC. ETC. ETC.! :-(
end;
end;
This is an extremely INEFFICIENT way to make this work for all Control Types because I would have to enumerate all existent Control Types, as TControl
does not have a TFont
property.
A better way would be to get the TFont
property of the control without having to ask for the TYPE and then having to TYPECAST the Control.
But HOW?