Context:
Using a personal application made in delphi-7 , I was adding new actions as needed on a TRadioGroup
, but now it contains many items (16), harming the usability of the application.
What I wanted to do would be to categorize these items from TRadioGroup
into TComboBox
, so I would have some categories and TRadioGroup
would be
less options, thus improving visual layout and making it easier to choose.
Need:
Create a TComboBox
dynamically based on a .ini
file, as if
was a configuration for loading 'TComboBox, it would look something like this:
[CATEGORIA]
0=CATEGORIA1
1=CATEGORIA2
2=CATEGORIA3
With the category defined and loading in TComboBox
then load the items from TRadioGroup
based on the group, a .ini
, more or less so, I thought:
[CATEGORIA_1]
0=ITEM1
1=ITEM2
[CATEGORIA_2]
0=ITEM1
1=ITEM2
2=ITEM3
3=ITEM4
4=ITEM5
[CATEGORIA_3]
0=ITEM1
1=ITEM2
2=ITEM3
Currently my code using the INI is only to save the last selected option, and when reopening the program already bring:
.INI
[CONFIG]
INDEXGROUP=1
Procedure SalvarINI
:
procedure SalvarINI;
var
vlIni: TIniFile;
begin
try
vlIni := TIniFile.Create(ExtractFileDir(Application.ExeName) +'\'+ ExtractFileName(Application.ExeName)+'.ini');
try
vlIni.WriteInteger('CONFIG', 'INDEXGROUP',rgItens.ItemIndex);
vlIni.UpdateFile;
finally
vlIni.Free;
end;
except
on e: exception do
begin
ShowMessage('Ops..não conseguimos Salvar as configurações: '+ e.Message);
end;
end;
end;
carregarINI
procedure carregarIni;
var
vlIni: TIniFile;
begin
vlIni := TIniFile.Create(ExtractFileDir(Application.ExeName) +'\'+ ExtractFileName(Application.ExeName)+'.ini');
try
RGProduto.ItemIndex := vlIni.ReadInteger('CONFIG' ,'INDEXGROUP',1);
finally
FreeAndNil(vlIni);
end;
end;
Thank you