Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Overriding onclick event for all components on form

898 views
Skip to first unread message

Adrian Wreyford

unread,
Nov 17, 1997, 3:00:00 AM11/17/97
to

How do I override the onclick event for all the components on a form,
without having to hardcode each event?
I can override the onclick for the form, but not inherited by all the
components on the form. I want to implement a help cursor, Word style,
that when clicked changes the cursor to crHelp, and then while the
cursor is in this state, I want it to give the component focus when
clicked, and then execute an F1 keypress, but not execute the standard
onclick event for that component.
Ive tried the following for Form1
type
THelpForm = class(TForm)
procedure Click; override;
end;
type Form1 = class(THelpForm)....
end;
procedure THelpForm.Click;
begin
if Screen.Cursor = crHelp then
Form1.Edit1.text := 'HELP'
else
inherited Click; { perform standard handling, including calling
handler }
end;
Well this works just fine for the form itself, but not for the buttons
on the form etc... and I don't want to have to hardcode every button
on the forms onclick event... Is it possible for them to inherit this
click override!!

Xavier Pacheco (TeamB)

unread,
Nov 18, 1997, 3:00:00 AM11/18/97
to

>> How do I override the onclick event for all the components on a form,
without having to hardcode each event?<<

That's going to be tricky. The only thing I can think of is to
create a single OnClick event handler that each component refers to.
Then, based on conditional statements, this event handler could call
an appropriate method for the various controls. If you want to do
something special in the event handler, you could always have the
event handler call another method altogether. Seems a bit rough but
it would be better than modifying many event handlers.

--- x
Xavier Pacheco (TeamB)
Sorry but TeamB cannot answer support questions received via email.

Mark Richter

unread,
Nov 18, 1997, 3:00:00 AM11/18/97
to

In addition to what Xavier suggests, you may be able to get around having
to 'hard' assign the event handler by walking through the form's component
list. Testing each component's type and making a software assignment would
significantly reduce the association time.

for x := 0 to ComponentCount-1 do
if (Components[x] is TButton) or
(Components[x] is TEdit)
then
...

Mark Richter
eMCee Software

Xavier Pacheco (TeamB) <xav...@xap.cnchost.com> wrote in article
<34713385...@forums.borland.com>...

Peter Below

unread,
Nov 18, 1997, 3:00:00 AM11/18/97
to

Adrian,

you are going at this problem from the wrong angle, i think. If you go into
help context mode by sending a WM_SYSCOMMAND message with wparam =
SC_CONTEXTHELP to your form (or have the user press the help border icon)
Windows takes over and when the user clicks on a control (actually it has
to be a TWinControl descendant) Windows sends a WM_HELP message to this
control. Delphi already handles this, if the control has a HelpContext <> 0
and the Application.Helpfile property is set to a help file name Delphi
automatically calls Application.HelpContext for you.

The problem are controls without a window handle (speedbuttons for example)
and the main menu. You can handle them by adding special case code to their
OnClick handlers that tests a flag you set when you go into help context
mode.

Your proposed solution (replacing all OnClick handlers) is in fact
workable, i think, but has a number of problems. Of course you need a way
to save all the existing OnClick handlers before you replace them with the
context-help specific handler, so you can restore them later. Dealing with
the handlers would involve a recursive scan over the Controls property of
the form and all controls you find (OnClick is a property of TControl).
The tricky part is to make absolutely sure you detect all ways the user can
get *out* of context help mode, so you can restore all the old handlers to
have your form back in normal operational mode.

Peter Below (TeamB) 10011...@compuserve.com)


Adrian Wreyford

unread,
Nov 19, 1997, 3:00:00 AM11/19/97
to

Thanks Peter... this is just what I wanted to hear.
Now.. for a silly question, but a real stumbling block for me!
How do I dispatch the WM_SYSCOMMAND message with wparam =
SC_CONTEXTHELP to the form, and does this automatically change the
cursor to crHelp, or do I have to do that. This winapi stuff still
keeps me on my knees!

Thanks once again.

Adrian

Peter Below <10011...@compuserve.com> wrote in message ...

Adrian Wreyford

unread,
Nov 19, 1997, 3:00:00 AM11/19/97
to

Got it!

SendMessage(Form1.handle,WM_SYSCOMMAND,SC_CONTEXTHELP,0);

PS Peter this works just fine.. will look into the help for speed
buttons as you recommended!
And yes it does change the cursor to crHelp.
The BorderIcons property allows one to set biHelp, but then the form
defaults to a dialog form...this way the form is still resizeable, and
also works with HTML help using components from Hyperact.

Adrian Wreyford wrote in message <64ve8l$v...@forums.borland.com>...

0 new messages