what is wrong there?
procedure TForm1.VCLHelpClick(Sender: TObject);
var Ctrl : TWinControl;
begin
Ctrl := FindVCLWindow(Mouse.CursorPos);
if Ctrl <>
Working code:
procedure TForm1.VCLHelpClick(Sender: TObject);
var WCtrl : TWinControl;
begin
WCtrl := FindVCLWindow(Mouse.CursorPos);
if WCtrl <> nil then
Application.HelpCommand(HELP_CONTEXT, wCtrl.HelpContext);
end;
P.S. all previous code probobly was ok too, but i rechecked my event handlers and found that in one tlabel it was missing ( althought when I clicked to the ones that had onclick, it did not work). Plus ... problem probobly was the faulty cursor check.
Ok, thanks for support, guys!
Have you tried debugging the code? And can you tell us what part went wrong.
Besides, why don't you use the helpcontext like:
procedure TForm1.VCLHelpClick(Sender: TObject);
var Ctrl : TWinControl;
begin
if Form2.Cursor <> crHelp then // Are you sure this is Form2???
Exit;
Ctrl := FindVCLWindow(Mouse.CursorPos);
if Ctrl = nil then Exit;
Application.HelpCommand(HELP_CONTEXT, Ctrl.HelpoContext);
end;
Looks like FindVCLControl does some other things. But the following code works:
procedure TForm1.Button1Click(Sender: TObject);
var
ctrl : TControl;
point : TPoint;
begin
point := Mouse.CursorPos; // Mouse pos at screen
Dec(point.X, Left); // Adjust for window.
Dec(point.Y, Top);
Dec(point.Y, GetSystemMetrics(SM_CYCAPTION)); // Adjust to client area.
ctrl := ControlAtPos(point, True, True, True);
// Do something with the control
end;
You probably need some more tweaking, but this works to get the control of a window from the position.