Solved

OnClick event doesn't work

Posted on 1998-08-23
3
340 Views
Last Modified: 2010-04-04
when I place a TButton on TStringGrid like this:

Button1.Parent:=StringGrid1;

then, the OnClick Event of the Button doesn't work.
With SpeedButtons it works fine.
Any ideas?
0
Comment
Question by:ronit051397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
ID: 1337474
Hi,
This is a simple solution. You could inherit the TButton and add the ControlStyle line to the decendant constructor if you want:

procedure TForm1.MyButtonClick(Sender: TObject);
begin
  ShowMessage( 'I work!' );
end;

procedure TForm1.FormCreate(Sender: TObject);
  ...
  with TButton.Create( Self ) do begin
    ControlStyle := ControlStyle + [csClickEvents]; // add this!
    Parent := StringGrid1;
    with StringGrid1.CellRect( 1, 1 ) do SetBounds( Left, Top, Right - Left + 1, Bottom - Top + 1 );
    Caption := 'My button';
    OnClick := MyButtonClick;
  end;
end;

/// John
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1337475
Thanks.
Do you know why this is working with TPanel but not working with TStringGrid?
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1337476
For some reason, this is not working with TUpDown Component. Do you know why?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question