Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Ayuda INI Files (https://www.clubdelphi.com/foros/showthread.php?t=87120)

obum1 17-11-2014 01:18:50

Ayuda INI Files
 
Hola amigos tengo una problema con los inifiles a la hora de que el programa lo lea por ejemplo:

[secion]
iden=dfakldsjklñdajklñfdsajklfdsajklfdsajklfdsaklñfdsajklñdsafjklfjlkfñalkdsf <======== Valor.

al crear todo el proecedmiento y cargar la ini a un edit lo que sucede, que no carga todo el string si no casi muy
poco por ello queria saber como solucionarlo ya que no deja cargargar todo. Gracias.

escafandra 17-11-2014 01:58:42

¿Que código estás usando?

Saludos.

obum1 17-11-2014 03:17:09

dsa
 
var
ini : tinifiles
begin
ini := tinifiles. create(exfilepatch(exename)+'key.key');
edit1.text := ini.readstring('ubicacion','llave',''
end;
esta es el codigo que uso para cargar pero no carga completamente el string si no a medias

nlsgarcia 17-11-2014 03:41:45

obum1,

Cita:

Empezado por obum1
...tengo una problema con los inifiles a la hora de que el programa lo lea...no carga todo el string...a un edit...

:rolleyes:

Pregunto:

1- ¿Que versión de Windows y Delphi utilizas?.

2- ¿El componente TEdit en cuestión, tiene la propiedad MaxLength con algún valor diferente de cero?.

3- ¿Has hecho un debug para verificar si los valores son leídos correctamente del archivo .ini? :confused:

4- ¿Puedes publicar el código real que usas en el programa?, el código que publicastes en el Msg #3 no es el correcto :cool:

Revisa este código:
Código Delphi [-]
// GUARDANDO OPCIONES EN UN ARCHIVO INI

procedure TFPrincipal.GuardarINI;
var INI: TIniFile;
begin
  // Creamos el archivo INI
  INI := TINIFile.Create( ExtractFilePath( Application.ExeName ) + 'opciones.ini' );

  // Guardamos las opciones
  INI.WriteString( 'OPCIONES', 'IMPRESORA', IMPRESORA.Text );
  INI.WriteInteger( 'OPCIONES', 'COPIAS', COPIAS.Value );
  INI.WriteBool( 'OPCIONES', 'VISTAPREVIA', VISTAPREVIA.Checked );
  INI.WriteDate( 'OPCIONES', 'FECHA', FECHA.Date );
  INI.WriteTime( 'OPCIONES', 'HORA', StrToTime( HORA.Text ) );
  INI.WriteFloat( 'OPCIONES', 'MARGEN', MARGEN.Value );

  // Al liberar el archivo INI se cierra el archivo opciones.ini
  INI.Free;
end;

// CARGANDO OPCIONES DE UN ARCHIVO INI

procedure TFPrincipal.CargarINI;
var INI: TIniFile;
begin
  // Si no existe el archivo no hacemos nada
  if not FileExists( ExtractFilePath( Application.ExeName ) + 'opciones.ini' ) then
    Exit;

  // Creamos el archivo INI
  INI := TINIFile.Create( ExtractFilePath( Application.ExeName ) + 'opciones.ini' );

  // Guardamos las opciones
  IMPRESORA.Text := INI.ReadString( 'OPCIONES', 'IMPRESORA', '' );
  COPIAS.Value := INI.ReadInteger( 'OPCIONES', 'COPIAS', 0 );
  VISTAPREVIA.Checked := INI.ReadBool( 'OPCIONES', 'VISTAPREVIA', False );
  FECHA.Date := INI.ReadDate( 'OPCIONES', 'FECHA', Date );
  HORA.Text := TimeToStr( INI.ReadTime( 'OPCIONES', 'HORA', Time ) );
  MARGEN.Value := INI.ReadFloat( 'OPCIONES', 'MARGEN', 0.00 );

  // Al liberar el archivo INI se cierra el archivo opciones.ini
  INI.Free;
end;
Tomado de : Delphi al Límite - Guardando y cargando opciones

Espero sea útil :)

Nelson.

ecfisa 17-11-2014 03:42:45

Hola obum1.

Por favor vuelve a leer la Guía de estilo y cuando incluyas código en tus mensajes usa las etiquetas como explica la imágen:



Ese código no puede siquiera ser compilado, te señalo los errores de sintáxis:
Código Delphi [-]
var
  ini : tinifiles //;
begin
  ini := tinifiles.{ }create(exfilepatch(exename)+'key.key');
  edit1.text := ini.readstring('ubicacion','llave','' // );
end;

La sintáxis correcta:
Código Delphi [-]
var
  ini : TiniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(Application.ExeName)+'key.key');
  Edit1.Text := ini.ReadString('ubicacion','llave','');
end;
Eso como para que compile, pero no puedo asegurar que los valores obtenidos sean correctos... También sería necesario ver como se guardan los valores.

Saludos :)

obum1 17-11-2014 19:09:49

Cita:

Empezado por nlsgarcia (Mensaje 484919)
obum1,


:rolleyes:

Pregunto:

1- ¿Que versión de Windows y Delphi utilizas?.

2- ¿El componente TEdit en cuestión, tiene la propiedad MaxLength con algún valor diferente de cero?.

3- ¿Has hecho un debug para verificar si los valores son leídos correctamente del archivo .ini? :confused:

4- ¿Puedes publicar el código real que usas en el programa?, el código que publicastes en el Msg #3 no es el correcto :cool:

Revisa este código:
Código Delphi [-]
// GUARDANDO OPCIONES EN UN ARCHIVO INI

procedure TFPrincipal.GuardarINI;
var INI: TIniFile;
begin
  // Creamos el archivo INI
  INI := TINIFile.Create( ExtractFilePath( Application.ExeName ) + 'opciones.ini' );

  // Guardamos las opciones
  INI.WriteString( 'OPCIONES', 'IMPRESORA', IMPRESORA.Text );
  INI.WriteInteger( 'OPCIONES', 'COPIAS', COPIAS.Value );
  INI.WriteBool( 'OPCIONES', 'VISTAPREVIA', VISTAPREVIA.Checked );
  INI.WriteDate( 'OPCIONES', 'FECHA', FECHA.Date );
  INI.WriteTime( 'OPCIONES', 'HORA', StrToTime( HORA.Text ) );
  INI.WriteFloat( 'OPCIONES', 'MARGEN', MARGEN.Value );

  // Al liberar el archivo INI se cierra el archivo opciones.ini
  INI.Free;
end;

// CARGANDO OPCIONES DE UN ARCHIVO INI

procedure TFPrincipal.CargarINI;
var INI: TIniFile;
begin
  // Si no existe el archivo no hacemos nada
  if not FileExists( ExtractFilePath( Application.ExeName ) + 'opciones.ini' ) then
    Exit;

  // Creamos el archivo INI
  INI := TINIFile.Create( ExtractFilePath( Application.ExeName ) + 'opciones.ini' );

  // Guardamos las opciones
  IMPRESORA.Text := INI.ReadString( 'OPCIONES', 'IMPRESORA', '' );
  COPIAS.Value := INI.ReadInteger( 'OPCIONES', 'COPIAS', 0 );
  VISTAPREVIA.Checked := INI.ReadBool( 'OPCIONES', 'VISTAPREVIA', False );
  FECHA.Date := INI.ReadDate( 'OPCIONES', 'FECHA', Date );
  HORA.Text := TimeToStr( INI.ReadTime( 'OPCIONES', 'HORA', Time ) );
  MARGEN.Value := INI.ReadFloat( 'OPCIONES', 'MARGEN', 0.00 );

  // Al liberar el archivo INI se cierra el archivo opciones.ini
  INI.Free;
end;
Tomado de : Delphi al Límite - Guardando y cargando opciones

Espero sea útil :)

Nelson.

bueno es similaar a tu codigo, el problema guarda el ini pero cargar carga el string al edit pero no completamente y el edit esta por deafault no modifique ningun valor en maxlength.

nlsgarcia 17-11-2014 19:20:32

obum1,

Cita:

Empezado por obum1
...es similar a tu código...no modifique ningún valor en MaxLength...

:rolleyes:

Pregunto:

1- ¿Que versión de Windows y Delphi utilizas?.

2- ¿Has hecho un debug para verificar si los valores son leídos correctamente del archivo .ini? :confused:

Espero sea útil :)

Nelson.


La franja horaria es GMT +2. Ahora son las 22:16:48.

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