INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Finding a component and setting its font properties

Finding a component and setting its font properties

(OP)
Hi,

Simple button click handler that applies to several buttons on a page.

The code determines which (speed)button is pressed (all have a numeric suffix (e.g. MainButton1, MainButton2 etc) and then displays a corresponding Tabsheet. That bit works ok, but I am also trying to set the font properties of the buttons, such that the pressed button's font is coloured and bold, and the other buttons are set to default (black and non-bold).

CODE -->

procedure TForm1.MainButtonClick(Sender: TObject);
var
i, j, k : integer;
sName, sTab, sBtn, sNo : string;   //for testing
sl : Tstringlist ;
begin
sl := Tstringlist.Create;
for i := 0 to ComponentCount-1 do
  begin
  if Components[i] is TSpeedButton then
    sl.add((Components[i] as TSpeedButton).Name);
  end;
sName := TComponent(Sender).Name;
sNo := copy(sName, length(sName),1);
i := StrToInt(sNo);
for j := 0 to sl.count-1 do
  begin
  k := j+1;
  if i = strToInt(copy(sl[j], length(sl[j]),1)) then
    begin
    sTab := 'TabSheet'+ IntToStr(i);
    PageControl1.ActivePage := (FindComponent(sTab) As TTabSheet);
    end;
  with TSpeedButton(sl[j]) do
    begin
    if i = k then Font.Color := clBlue else Font.Color := clBlack;
    if i = k then Font.style := [fsBold] else Font.style:=[];
    end;
  end;
sl.Destroy;
end; 

It all works until it gets to the first "if i = k ..." line and then it throws an exception error.

I know it is probably something simple, but have not used Delphi in about 5 years.

Thanks for any suggestions

Roger

RE: Finding a component and setting its font properties

(OP)
Sorted it - so everyone can stand down!

used:
with FindComponent(sl[j])As TSpeedButton do

instead of
with TSpeedButton(sl[j]) do

Cheers

Roger

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close