Hola wiwaedu.
Podrías hacer:
Código Delphi
[-]
...
implementation
const
EDS_LBS = 14; ...
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i : Integer;
ed : TEdit;
lb : TLabel;
begin
with TStringList.Create do
try
for i:= 1 to EDS_LBS do
begin
ed := TEdit( FindComponent('Edit' + IntToStr( i )) );
lb := TLabel( FindComponent('Label' + IntToStr( i )) );
if Assigned( ed ) then Add( ed.Text );
if Assigned( lb ) then Add( lb.Caption );
end;
SaveToFile( ExtractFilePath( Application.ExeName ) + 'config.txt' );
finally
Free;
end;
end;
Pero, como opción, almacenar los datos en un archivo .ini (o el registro de windows) te resultará una herramienta mas poderosa.
Como veo que has encarado el asunto mediante un archivo, te pongo un ejemplo con IniFiles en el que se guarda el texto de los componentes y también su color:
Código Delphi
[-]
...
implementation
uses Inifiles;
const
EDS_LBS = 14;
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
lb: TLabel;
ed: TEdit;
begin
with TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini') do
try
for i := 1 to EDS_LBS do
begin
lb := TLabel( FindComponent( 'Label' + IntToStr(i) ) );
ed := TEdit ( FindComponent( 'Edit' + IntToStr(i) ) );
if Assigned(lb) then
begin
lb.Caption := ReadString(lb.Name,'Caption',lb.Name);
lb.Color := ReadInteger(lb.Name,'Color', Color);
end;
if Assigned(ed) then
begin
ed.Text := ReadString(ed.Name,'Text', ed.Name);
ed.Color := ReadInteger(ed.Name,'Color', clWindow);
end;
end;
finally
Free;
end;
Randomize;
end;
procedure TForm1.BtnChangeColorClick(Sender: TObject);
const
CCOLOR : array [1..10] of TColor = (clWindow, clLime, clRed, clBlue, clGray,
clFuchsia, clAqua, clYellow, clSilver, clOlive);
var
lb: TLabel;
ed: TEdit;
i: Integer;
begin
for i:= 1 to EDS_LBS do
begin
lb := TLabel( FindComponent( 'Label' + IntToStr(i) ) );
ed := TEdit( FindComponent( 'Edit' + IntToStr(i) ) );
if Assigned(lb) then lb.Color := CCOLOR[Random(10)+1];
if Assigned(ed) then ed.Color := CCOLOR[Random(10)+1];
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i : Integer;
lb: TLabel;
ed: TEdit;
begin
with TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini') do
try
for i := 1 to EDS_LBS do
begin
lb := TLabel( FindComponent( 'Label' + IntToStr(i) ) );
ed := TEdit ( FindComponent( 'Edit' + IntToStr(i) ) );
if Assigned(lb) then
begin
WriteString(lb.Name,'Caption', lb.Caption);
WriteInteger(lb.Name,'Color', lb.Color);
end;
if Assigned(ed) then
begin
WriteString(ed.Name,'Text', ed.Text);
WriteInteger(ed.Name,'Color', ed.Color);
end;
end;
finally
Free;
end;
end;
Así también podrías guardar las posiciónes de los controles, la fuente de su texto, tamaño y demás propiedades como visibilidad, etc.
Saludos