Author: Jonas Bilinkevicius
I have three single TRadioButtons sitting on a TPanel (on Form1). How can I save
the state of the checked TRadioButton to a TIniFile and read it back afterwards? I
know how to do it with a TRadioGroup, but not with stand-alone radiobuttons.
Answer:
1 uses2 IniFiles;
3 4 procedure SaveRadioButtonState;
5 var6 data: TIniFile;
7 K: Integer;
8 begin9 data := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'test.ini');
10 try11 for K := 0 to form1.ComponentCount - 1 do12 if Form1.Components[K] is TRadioButton then13 {We only look for the checked radiobutton and save its state, of course}14 data.WriteBool('Options', IntToStr(K),
15 TRadioButton(Form1.Components[K]).Checked = True);
16 finally17 data.Free;
18 end;
19 end;
20 21 procedure ReadRadioButtonState;
22 var23 data: TIniFile;
24 K: Integer;
25 begin26 data := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'test.ini');
27 try28 for K := 0 to Form1.ComponentCount - 1 do29 if Form1.Components[K] is TRadioButton then30 TRadioButton(form1.Components[K]).Checked := data.ReadBool('Options',
31 IntToStr(K), True);
32 finally33 data.Free;
34 end;
35 end;