Hi,
Isn't is much easier to give every SpeedButton a unique tag (with the
Tag-property) and use
that in an OnClick-event?
Procedure TForm1.ButtonClick(Sender: TObject);
Begin
If Assigned(Sender) And
(Sender Is TSpeedButton) Then
Case TSPeedButton(Sender).Tag Of
1 : DoSomeThing1;
2 : DoSomeThing2;
...
End;
End;
Or you could even use (depending on de rest of the code):
Begin
If Assigned(Sender) And
(Sender Is TSpeedButton) And
(TSpeedButton(Sender).Tag > 0) Then
With TSpeedButton(Sender) Do
Caption := StrList[Tag];
End;
Greetz,
Peter.
-----Oorspronkelijk bericht-----
Van: [email protected] [mailto:[EMAIL PROTECTED]
Nesler, Thomas J
Verzonden: donderdag 6 maart 2008 17:34
Aan: [email protected]
Onderwerp: RE: [delphi-en] Locating Speedbutton controls
Hello!
I tried using this tip but I am getting a runtime error Einvalidcast
when I try to run my program. The error is Invalid Type Cast.
It appears that it does not like the Name property.
Here is how I am using your suggestion:
If (Sender as TSpeedbutton).Name = 'SpdBtn' + IntToStr(I+1) then
begin
case I+1 of
1: SpdBtn1.Caption := Strlist[1];
2: SpdBtn1.Caption := Strlist[2];
...
End;
End;
Any suggestions?
Tom Nesler