List Info

Thread: RE: Locating Speedbutton controls




RE: Locating Speedbutton controls
country flaguser name
United States
2008-03-06 10:34:02

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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
Behalf Of Charlie Chambers
Sent: Wednesday, March 05, 2008 6:39 PM
To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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: delphi-en-unsubscribe%40yahoogroups.com">delphi-en-unsubscribeyahoogroups.com
Yahoo! Groups Links

__._,_.___
.

__,_._,___
RE: Locating Speedbutton controls
country flaguser name
Netherlands
2008-03-06 10:50:49

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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com]Namens
Nesler, Thomas J
Verzonden: donderdag 6 maart 2008 17:34
Aan: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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

__._,_.___
.

__,_._,___
Re: Locating Speedbutton controls
country flaguser name
United States
2008-03-06 11:32:36

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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
Behalf Of Charlie Chambers
Sent: Wednesday, March 05, 2008 6:39 PM
To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
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: delphi-en-unsubscribe%40yahoogroups.com">delphi-en-unsubscribeyahoogroups.com
Yahoo! Groups Links

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )