Ah... now we're getting somewhere!
I didn't have a clue about what you
were trying to do ;)

In that case, this might be an option:

I just created a simple form for this with
on it 9 TSpeedButtons (no names set) with
their Tag-properties set from 1 to 9.

The OnFormShow-event has this code:

procedure TForm1.FormShow(Sender: TObject);
Var
  I  : Integer;
  SL : TStringList;
begin
  SL := TStringList.Create;
  Try
    SL.LoadFromFile('Captions.txt');
    For I := 0 To ComponentCount - 1 Do
      If (Self.Components[I] Is TSpeedButton) Then
        With TSpeedButton(Components[I]) Do
          If (Tag > 0) And
             (Tag <= SL.Count) Then
            Caption := SL[Tag - 1];
  Finally
    SL.Free;
  End;
end;

To fill the captions in a TList, I simply
created a little text-file with 9 captions
in it, but this list could be generated in
any way you like.


Note, however, that the OnShow-event isn't
good place to store this code, since it will
be fired everytime that the form is showed.
You'd better use the OnCreate-event or the
OnActivate- or OnShow-event with a global
RunOnce-boolean, so that the code will only
be run once...

procedure TForm1.FormShow(Sender: TObject);
Var
  I  : Integer;
  SL : TStringList;
begin
  If fRunOnce Then  // fRunOnce is a global
    Exit;           // boolean value set to
  fRunOnce := True; // false in the form-create

  SL := TStringList.Create;
  Try
...

If you want to see this example in action,
you can see a little demo-project here:
http://delphi.videoripper.org/SpeedBtnCaptions.zip


Greetz,

Peter.

-----Oorspronkelijk bericht-----
Van: [email protected] [mailto:[EMAIL PROTECTED]
Martin Wynne
Verzonden: donderdag 6 maart 2008 20:22
Aan: [email protected]
Onderwerp: [delphi-en] Re: Locating Speedbutton controls


Hi Tom,

> My code is part of the OnShow event of the form.

In that case the Sender will never be a TSpeedButton, so your
typecast (Sender as TSpeedButton) won't work.

Also TSpeedButton is a TGraphicControl, not a TWinControl.

You need to cycle through the components on the form and then do

if Component is TSpeedButton

if TSpeedButton(Component).Name =

regards,

Martin.

Reply via email to