Board index » delphi » D1: TButton "OnClick" fails when parent is TStringGrid: Why?

D1: TButton "OnClick" fails when parent is TStringGrid: Why?

I'm working in Delphi 1.  For various reasons I won't go into here, I
want to float a TButton over a cell of a TStringGrid.  I was having
problems with it, so I created a very simple testbed:

  TForm1 = class(TForm)
    TestButton: TButton;
    StringGrid1: TStringGrid;
    MoveButton: TButton;
    Panel1: TPanel;
    procedure TestButtonClick(Sender: TObject);
    procedure MoveButtonClick(Sender: TObject);
    procedure TestButtonKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);

TestButton is located at (0,0) of Form1, so that it will be positioned
properly over the other components if it is moved; otherwise, the
positions of the components do not matter.  

To see if TestButton is responding property, I simply listen:

procedure TForm1.TestButtonClick(Sender: TObject);
begin
   MessageBeep(0)
end;

procedure TForm1.TestButtonKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   MessageBeep(0)
end;

When I mouseclick TestButton, I hear a small sound.  If the focus is on
MouseButton and I press the space bar, I also hear the sound.

MoveButton is used to relocate TestButton, as follows:

procedure TForm1.MoveButtonClick(Sender: TObject);
begin
   with TestButton do
    case Tag of
      0: begin Parent:=StringGrid1; Tag:=1 end;
      1: begin Parent:=Panel1; Tag:=2 end;
      2: begin Parent:=Form1; Tag:=0 end;
      end;
end;

When I click MoveButton, TestButton moves around, as expected.  Now,
after moving TestButton, I try leftclicking it.  No matter which of the
three positions it is in, it visually indicates that it is being
pressed; the image of the button moves slightly under the mouse cursor.
However, when the parent of TestButton is the string grid, the feedback
beeps disappear.  When I press the space bar (with the focus on
TestButton), the feedback beeps do not disappear.  I have also done the
test with OnMouseDown rather than OnClick, and then the beeps do not
disappear.

All four of TButton, TForm, TStringGrid, and TPanel have OnMouseDown,
OnClick, and OnKeyDown events.

If I disable StringGrid1, then TestButton remains visible, but
leftclicking it does not even cause the image to move under the cursor.

Can anyone explain to me
1. Why am I losing OnClick behaviour for a TButton that has a string
grid as a parent?
2. Is there any straightforward way to regain the OnClick behavour?

Please mail replies in addition to posting them; my news server has a
short attention span and the weekend is coming soon.

--
Howard L. Kaplan
Psychopharmacology and Dependence Research Unit
Women's College Hospital
76 Grenville Street, 9'th floor
Toronto, Ontario
Canada  M5S 1B2
(416)323-6400, ext 4915
howard.kap...@utoronto.ca

 

Re:D1: TButton "OnClick" fails when parent is TStringGrid: Why?


On Thu, 16 Oct 1997 19:48:05 GMT, Howard Kaplan

Quote
<howard.kap...@utoronto.ca> wrote:
>I'm working in Delphi 1.  For various reasons I won't go into here, I
>want to float a TButton over a cell of a TStringGrid.  I was having
>problems with it, so I created a very simple testbed:

I posted something that might be of help to you. It's in this latest
batch of replies and is under the subject...

Re: TNeedHelp.Create('DrawCell & Painting problem');

JE McTaggart

Other Threads