views:

229

answers:

2

what is wrong there?

procedure TForm1.VCLHelpClick(Sender: TObject);
var Ctrl : TWinControl;
 begin
 Ctrl := FindVCLWindow(Mouse.CursorPos);
 if Ctrl <> nil then
  if Form2.Cursor = crHelp then begin
   if Ctrl = CreatorEdit then Application.HelpCommand(HELP_CONTEXT,001);
   if Ctrl = EditorEdit then Application.HelpCommand(HELP_CONTEXT,002);
   if Ctrl = UpdaterEdit then Application.HelpCommand(HELP_CONTEXT,003);
   if Ctrl = IdeaEdit then Application.HelpCommand(HELP_CONTEXT,004);
   if Ctrl = PorterEdit then Application.HelpCommand(HELP_CONTEXT,005);
  end;
 end;

The idea is simple - i have form border icons for Help button and when i click it, cursors changes to crHelp. If i click under control for any of IFs, it invokes Help System and Opens associated help file with context from command. But it doesnt work ... Is this because I have not added support for KLink / ELinks in Help file itself?

For help authoring and developing I am using ShalomHelpMaker Software.

+2  A: 

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.

Gamecat
Hmmm, I stepped it recently and it did not detect Control.And I did not used this ( short ) form because the form2 is dynamic and I added requiered context id at runetime so when I need to find it, I need to browse ( scrool ) all over my code. In this case I can read excatly what ID I am opening whithout search for HelpContext ID value assigning.
HX_unbanned
Just tried your code. Doesn't work.
HX_unbanned
@HX_Unbanned, looks like FindVCLWindow is the problem. I put an alternative in my answer.
Gamecat
Hmmm, Okay, I'll try! And, of course, - Thank you!
HX_unbanned
A: 

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!

HX_unbanned