There are several ways and / or places to store this type of data:
-
Database : For this you must use database access components.
-
Files on disk (INI) : For this Delphi has classes to work with INI files (
TIniFile
).
-
Windows Registry : For this you can use the class that also comes with Delphi (
TRegistry
).
- ...
With the components that you comment on RxLib , you can do it in the registry or in INI files, since they implement both options.
If you want to try to do it by hand, for example using an INI file, you can use a couple of procedures like these.
In the uses of your unit
add:
uses
Inifiles;
In the public part of your form, add 2 procedures:
procedure GuardarEstado();
procedure RecuperarEstado();
The implementation will be somewhat similar to this:
procedure Tfrm1.RecuperarEstado();
var
iniF:TIniFile;
fName:String;
begin
// El fichero se llamará igual que la aplicación pero extensión INI
fName := ChangeFileExt(Application.ExeName, '.INI');
// Tenemos que comprobar si el fichero existe...
if FileExists(FName) then begin
// Crear el fichero
iniF := TIniFile.Create(fName);
// Proteccion para liberar
try
// Recuperar los valores....
edtDescripcion.Text := iniF.ReadString('CONFIG', 'Nombre', '');
edtCodigo.Text := iniF.ReadString('CONFIG', 'Codigo', '');
... <= El resto de elementos a recuparar
finally
// Liberarlo
FreeAndNil(iniF);
end;
end;
end;
procedure Tfrm1.GuardarEstado();
var
iniF:TIniFile;
fName:String;
begin
// El fichero se llamará igual que la aplicación pero extensión INI
fName := ChangeFileExt(Application.ExeName, '.INI');
// Crear el fichero
iniF := TIniFile.Create(fName);
// Proteccion para liberar
try
// Guardar los valores...
iniF.WriteString('CONFIG', 'Nombre', edtDescripcion.Text);
iniF.WriteInteger('CONFIG', 'Codigo', StrToInt(edtCodigo.Text));
... <= Los elementos que quieras guardar
finally
// Liberarlo
FreeAndNil(iniF);
end;
end;
You should be adding more components in each procedure. As many as you want to store.
Finally, for example, in the OnShow
of your form, you should call the procedure RecuperarEstado
, and in the OnClose
of the forms at GuardarEstado
.
In my case, once the state is saved, in the same place where the EXE is generated, an .INI file appears with a content like this:
[CONFIG]
Code = 1
Name = SEUR
As you add more components and properties, they will be stored in this file.