Esta rotina desenvolvi para guarda os valores de uma tela.

Neste caso apenas os Edit com a TAG = 1 são gravados.

(*
Para carregar os TstringList;

vArquivoINI.ReadSection('Section', idComponent);{ Carrego a lista de 
componentes }
for vIntCountId := 0 to idComponent.Count - 1 do
begin
  { Carrego a lista de valores }
  idValue.Add(vArquivoINI.ReadString('Section', 
idComponent[vIntCount].Strings[vIntCountId], ''));
end;
*)

Uses: IniFiles;


Private
    idComponent: TStringList;
    idValue: TStringList;


procedure GravaIni;
var
   vIntCount    : Integer;
   vArquivoINI  : TIniFile;
   vNomeArquivo : String;
   vSearchRec   : TSearchRec;

begin

     Try
        FindFirst(Application.ExeName, 0, vSearchRec);
        vNomeArquivo := Copy(vSearchRec.Name, 1, Length(vSearchRec.Name) - 4);
        FindClose(vSearchRec);
        vArquivoINI := TIniFile.Create(ExtractFilePath(Application.ExeName) + 
'\' + vNomeArquivo + '_CFG.ini');
        for vIntCount := 0 to ComponentCount - 1 do
        try
           if (Components[vIntCount] is TComboBox) then
           begin
              vArquivoINI.WriteInteger(FFilePrefix, (Components[vIntCount] as 
TComboBox).Name, (Components[vIntCount] as TComboBox).ItemIndex);
           end;
           if (Components[vIntCount] is TEdit) and ((Components[vIntCount] as 
TEdit).Tag = 1) then
           begin
              vArquivoINI.WriteString(FFilePrefix, (Components[vIntCount] as 
TEdit).Name, (Components[vIntCount] as TEdit).Text);
           end;
           if (Components[vIntCount] is TCheckBox) then
           begin
              vArquivoINI.WriteBool(FFilePrefix, (Components[vIntCount] as 
TCheckBox).Name, (Components[vIntCount] as TCheckBox).Checked);
           end;
           if (Components[vIntCount] is TTrackBar) then
           begin
              vArquivoINI.WriteString(FFilePrefix, (Components[vIntCount] as 
TTrackBar).Name, IntToStr((Components[vIntCount] as TTrackBar).Position));
           end;
        except
        end;
        FreeAndNil(vArquivoINI);
     except
        on E : Exception do
        begin
           MsgErro(E.Message);
        end;
     end;

end;


procedure CarregaTela;
var
   vObjAux   : TObject;
   vIntCount : Integer;

begin

     for vIntCount := 0 to idComponent.Count - 1 do
     begin
        vObjAux := (FindComponent(idComponent.Strings[vIntCount]));
        if (vObjAux is TComboBox) then
        begin
           TComboBox(vObjAux).ItemIndex := StrToInt(idValue.Strings[vintcount]);
        end;
        if (vObjAux is TEdit) then
        begin
           if (AnsiUpperCase((vObjAux as TEdit).Name) = 'EDTNETWORKPORT') and
              (AnsiUpperCase((vObjAux as TEdit).Text) = '0') then
              TEdit(vObjAux).Text := VerificaPorta
           else
              TEdit(vObjAux).Text := idValue.Strings[vintcount];
        end;
        if (vObjAux is TCheckBox) then
        begin
           TCheckBox(vObjAux).Checked := (idValue.Strings[vintcount] = '1');
        end;
        if (vObjAux is TTrackBar) then
        begin
           TTrackBar(vObjAux).Position := StrToInt(idValue.Strings[vintcount]);
        end;
     end;

end;
 

 
Eduardo Castro Alves
Analista de Sistemas



-- 
<<<<< FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM >>>>>

<*> Para ver as mensagens antigas, acesse:
    http://br.groups.yahoo.com/group/delphi-br/messages

<*> Para falar com o moderador, envie um e-mail para:
    [EMAIL PROTECTED]
 
Links do Yahoo! Grupos

<*> Para visitar o site do seu grupo na web, acesse:
    http://br.groups.yahoo.com/group/delphi-br/

<*> Para sair deste grupo, envie um e-mail para:
    [EMAIL PROTECTED]

<*> O uso que você faz do Yahoo! Grupos está sujeito aos:
    http://br.yahoo.com/info/utos.html

 


Responder a