Ver Mensaje Individual
  #2  
Antiguo 04-06-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
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 ZaneMs.

Creo que te sería mas simple usar TStringsList para manipular el archivo de texto, por ejemplo:
Código Delphi [-]
procedure TForm1.CrearBotones(aFileName: TFileName);
var
  c,b: Integer;
begin
  with TStringList.Create do
  try
    LoadFromFile(aFileName);
    c:= 0;
    b:= 1;
    while (c < Count) do
    begin
      if Strings[c] = 'ButtonCtrl' then
        with TButton.Create(Self) do
        begin
          Parent:= Self;
          Name:= 'MiBoton'+IntToStr(b);
          Left:= StrToIntDef(Strings[c+1],0);
          Top := StrToIntDef(Strings[c+2],0);
          Inc(c);
          Inc(b);
        end;
      Inc(c);
    end;
  finally
    Free;
  end;
end;
Pero de todos modos no te recomiendo trabajarlo de ese modo.


Delphi dispone de las clases TIniFile y TRegistry que hacen esa tarea mas simple y segura. Un ejemplo usando IniFiles:
Código Delphi [-]
...
uses IniFiles;

const
  INIFIL = 'C:\CARPETA\ARCHIVO.INI'; // Nombre de archivo

// Este procedimiento crea valores de los atributos  
// de los botones (cinco para el ejemplo)
procedure CrearIniFile;
var
  Ini: TIniFile;
  i: Integer;
  s: string;
begin
  with TIniFile.Create(INIFIL) do
  try
    for i:= 1 to 5 do
    begin
      s:= 'MiBoton'+IntToStr(i);
      WriteString(s, 'Name', s);
      WriteInteger(s,'Left',100);
      WriteInteger(s,'Top', 50*i+25);
      WriteInteger(s,'Height',25);
      WriteInteger(s,'Width',90);
      WriteString(s,'Caption', s);
    end;
  finally
    Free;
  end;
end;

// Se crean los botones y se asignan a sus atributos 
// los valores almacenados en ARCHIVO.INI
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  s: string;
begin
   if not FileExists(INIFIL) then // Si no fueron definidos los valores,
     CrearIniFile;  //crearlos
  // Crear botones y obtener los valores de sus atributos
  with TIniFile.Create(INIFIL) do
  try
    for i:= 1 to 5 do
    begin
      with TButton.Create(Self) do
      begin
        Parent:= Self;
        s:= 'MiBoton'+IntToStr(i);
        Name:= ReadString(s,'Name','');
        Left:= ReadInteger(s,'Left',0);
        Top:= ReadInteger(s,'Top',0);
        Height:= ReadInteger(s,'Height',25);
        Width:= ReadInteger(s,'Width',70);
        Caption:= ReadString(s,'Caption','Botón');
      end;
    end;
  finally
    Free;
  end;
end;
...
Como te mencioné mas arriba lo mismo podes hacer usando TRegistry, en este enlace: referencia de tedit en TComponentList tenes un ejemplo con ambos modos.

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita