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).
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
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