Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-05-2015
wiwaedu wiwaedu is offline
Miembro
 
Registrado: ene 2007
Posts: 14
Poder: 0
wiwaedu Va por buen camino
Post Bucle de guardado de Edit's

Hola!! Llevo varios días intentándolo y no doy con las opciones... ¿Seria posible hacer un bucle para guardar estos Edit's y Label's en el mismo orden?
Código Delphi [-]
procedure TFormConfig.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  with TStringList.Create do
  try
    Add(Edit1.Text);
    Add(Label1.Caption);
    Add(Edit2.Text);
    Add(Label2.Caption);
    Add(Edit3.Text);
    Add(Label3.Caption);
    Add(Edit4.Text);
    Add(Label4.Caption);
    Add(Edit5.Text);
    Add(Label5.Caption);
    Add(Edit6.Text);
    Add(Label6.Caption);
    Add(Edit7.Text);
    Add(Label7.Caption);
    Add(Edit8.Text);
    Add(Label8.Caption);
    Add(Edit9.Text);
    Add(Label9.Caption);
    Add(Edit10.Text);
    Add(Label10.Caption);
    Add(Edit11.Text);
    Add(Label11.Caption);
    Add(Edit12.Text);
    Add(Label12.Caption);
    Add(Edit13.Text);
    Add(Label13.Caption);
    Add(Edit14.Text);
    Add(Label14.Caption);
    SaveToFile(ExtractFilePath(Application.ExeName)+'config.txt');
  finally
    Free;
end;
Para abrir el .txt si lo conseguí con este código:
Código Delphi [-]
procedure TFormConfig.FormCreate(Sender: TObject);
var
  List:TStringList;
    i,j,c:Integer;
begin
 i:=0;
 j:=1;
  List := TStringList.Create;
  try
    if FileExists(ExtractFilePath(Application.ExeName)+'config.txt') = True then
    begin
    List.LoadFromFile(ExtractFilePath(Application.ExeName)+'config.txt');
    for c := 0 to FormConfig.ComponentCount-1 do
    begin
      if FormConfig.Components[c].ClassName = 'TEdit' then
       begin
        TEdit(FormConfig.Components[c]).Text := List[i];
        i := i+2;
       end
      else if FormConfig.Components[c].ClassName = 'TLabel' then
       begin
        TLabel(FormConfig.Components[c]).Caption := List[j];
        j := j+2;
       end;
     end;
     end;
    finally
    List.Free;
  end;
end;
Gracias!!

Última edición por nlsgarcia fecha: 28-05-2015 a las 15:47:52. Razón: Sintaxis Delphi
Responder Con Cita
  #2  
Antiguo 28-05-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola wiwaedu.

Podrías hacer:
Código Delphi [-]
...
implementation

const
  EDS_LBS = 14; // Nro de Labels y Edits
...

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; // Nro de Labels y Edits


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;

// Cambiar el color de los controles de forma aleatoria
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
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #3  
Antiguo 04-06-2015
wiwaedu wiwaedu is offline
Miembro
 
Registrado: ene 2007
Posts: 14
Poder: 0
wiwaedu Va por buen camino
¡¡Muchisimas gracias me sirvió de gran ayuda!!
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
condicionar el guardado de un archivo DarkBlue Servers 2 19-06-2012 20:19:49
bucle entre edit.change y edit.change alremo81 Varios 2 07-04-2008 15:25:39
mantener el valor guardado Ariel03 OOP 3 23-06-2007 23:09:19
bucle dentro de un bucle Cosgaya Varios 2 06-06-2005 07:05:16
ir a un registro guardado previamente pepe2000 Tablas planas 7 14-01-2004 11:35:19


La franja horaria es GMT +2. Ahora son las 00:33:03.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi