Hi All,
Think there's still may be a problem with the code as you wrote
as your wanting to not check the sender but get the internal list from the form
of the components it contains.
I think this code might work better:
for C:=0 to Form1.ComponentCount-1 do begin
if Components[C] is TSpeedbutton then begin
//do something
end;
end;
Cheers,
Charlie
----- Original Message -----
From: David Smith
To: [email protected]
Sent: Thursday, March 06, 2008 11:56 AM
Subject: Re: [delphi-en] Locating Speedbutton controls
If you're going to cycle through all the components as Charlie showed
earlier, you have to check type first. I.E.
For i := 0 to form1.components.componentcount - 1 do
If (Sender is TSpeedbutton) Then
If (Sender as TSpeedbutton).Name = 'caption' Then //do something
else If (Sender as TSpeedbutton).Name = 'caption1' do //something else
Charlie Chambers <[EMAIL PROTECTED]> wrote: Hi Tom,
Looks like Peter showed another way that may work better for you but sounds
like to me the problem is that the sender is not a TSpeedbutton so... the
invalid type case issue. The name string as you've written it looks ok to me.
The code i send works better where you send all the TSpeedbuttons click
methods to one procedure and sort out which one your firing. You many want to
iterate all the components as my #3 suggestion. Depends on where you put the
code to make the changes for what your doing.
If i can help further... let me know.
Cheers,
Charlie
----- Original Message -----
From: Nesler, Thomas J
To: [email protected]
Sent: Thursday, March 06, 2008 10:34 AM
Subject: 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
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Charlie Chambers
Sent: Wednesday, March 05, 2008 6:39 PM
To: [email protected]
Subject: Re: [delphi-en] Locating Speedbutton controls
Hi Tom,
i think your looking for:
if (Sender as TSpeedbutton).Name='SpdBtn1' then
//do something
if you don't know the name of the component then when you create the
component set the Tag property to a known amount as 20-41 to find
components as
if (Sender as TSpeedbutton).Tag=21 then
//do something
Or you can iterate through all the components on the form as
for C:=0 to Form1.ComponentCount-1 do begin
if Components[C] is TSpeedbutton then begin
//do something
end;
end;
Cheers,
Charlie
----- Original Message -----
From: Nesler, Thomas J
To: [email protected]
Sent: Wednesday, March 05, 2008 4:26 PM
Subject: [delphi-en] Locating Speedbutton controls
Hello!
I have a Coolbar with 21speed buttons on it. I need to enter captions
on the fly for these speedbuttons. How can I find these buttons and
load the captions?
I know there is some kind of search find function but I can't seem to
locate it right now.
Thanks in advance!
Tom Nesler
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
[Non-text portions of this message have been removed]
---------------------------------
Never miss a thing. Make Yahoo your homepage.
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]