PDA

Ver la Versión Completa : Equivalente al INI de windows


hectorgn
06-05-2012, 00:56:20
Hola a todos:

Quiero guardar ciertos parámetros del sistema que son locales a cada equipo, antes usaba el INI pero como estoy empezando con delphi y tratando de hacer la aplicación lo mas portable posible espero me pueden recomandar que utilizar para guardar estos parametros locales

De antemano gracias

Hector Gonzalez

ecfisa
06-05-2012, 01:32:36
Hoa hectorgn y bienvenido a Club Delphi :)

Como a todos los que se inician te invitamos a que leas nuestra guía de estilo (http://www.clubdelphi.com/foros/guiaestilo.php).

Vamos a tu consulta...

Utilizando archivo .INI:

...
uses IniFiles;

procedure TForm1.FormCreate(Sender: TObject);
const // Resolucion de confección
Alto= 768;
Ancho= 1366;
begin
MRut.AdaptarResolucion(frMain, Alto, Ancho);
with TIniFile.Create(ExtractFilePath(Application.ExeName)+'TodoRubro.INI')do
try
Left := ReadInteger('FormLeft','Left',0);
Top := ReadInteger('FormTop','Top',0);
Height:= ReadInteger('FormHeight','Height',768);
Width := ReadInteger('FormWidth','Width',1024);
finally
Free;
end;
end;

...

procedure TForm1.FormDestroy(Sender: TObject);
begin
with TIniFile.Create(ExtractFilePath(Application.ExeName)+'TodoRubro.INI')do
try
WriteInteger('FormLeft','Left',Left);
WriteInteger('FormTop','Top',Top);
WriteInteger('FormHeight','Height',Height);
WriteInteger('FormWidth','Width',Width);
finally
Free;
end;
end;



Utilizando el registro de windows:

...
uses Registry;

procedure TForm1.FormCreate(Sender: TObject);
var
R: TRegistry;
begin
with TRegistry.Create do
try
RootKey:= HKEY_CURRENT_USER;
if OpenKey('MiAplicacion', false) then
begin
Left:= ReadInteger('FormLeft');
Top:= ReadInteger('FormTop');
Height:= ReadInteger('FormHeight');
Width:= ReadInteger('FormWidth');
end;
finally
CloseKey;
Free;
end;
end;

...

procedure TForm1.FormDestroy(Sender: TObject);
begin
with TRegistry.Create do
try
RootKey:= HKEY_CURRENT_USER;
OpenKey('MiAplicacion', True);
WriteInteger('FormLeft',Left);
WriteInteger('FormTop',Top);
WriteInteger('FormHeight',Height);
WriteInteger('FormWidth',Width);
finally
CloseKey;
Free;
end;
end;


Para ampliar mas revisá estos enlaces:

archivos ini (http://www.infonegocio.com/tudela2/delphiladero/docs/regini/regini2.htm)
el registro de windows (http://www.infonegocio.com/tudela2/delphiladero/docs/regini/regini1.htm)

Saludos.

maeyanes
07-05-2012, 15:55:20
Hola...

También podrías usar archivos XML para guardar la configuración de tu aplicación.



Saludos...