Ver Mensaje Individual
  #12  
Antiguo 06-05-2012
Fakedo0r Fakedo0r is offline
Registrado
NULL
 
Registrado: may 2012
Posts: 1
Reputación: 0
Fakedo0r Va por buen camino
Hola, gracias por tu codigo. Por cierto, desconocia ese error que con cuentas limitadas se producen errores. En todo caso, aqui te dejo una alternativa mia que no me ha dado ningun error hasta hora.

Código Delphi [-]
//******************************************************************************
//* UNIT:         UNT_GetWriteINI
//* AUTOR:        Fakedo0r
//* FECHA:        14.04.2012
//* CORREO:       Luvel88@gmail.com
//* BLOG:         Sub-Soul.blogspot.com
//* DESCRIPCION:  Permite Leer / Escribir ficheros tipo *.INI
//* USO:          GetINI('C:\Config.ini', 'Opciones', 'Puerto', '');
//*               WriteINI('C:\Config.ini', 'Opciones', 'Puerto', '5005');
//******************************************************************************
unit UNT_GetWriteINI;
//******************************************************************************
//DECLARACION DE LIBRERIAS / CLASES
//******************************************************************************
interface

uses
  Winapi.Windows, System.SysUtils;
//******************************************************************************
//DECLARACION DE FUNCIONES / PROCEDIMIENTOS
//******************************************************************************
function GetINI(sPath: String; sName: String; sKeyName: String; sDefault: String): String;
function WriteINI(sPath: String; sName: String; sKeyName: String; sValor: String): Bool;
//******************************************************************************
implementation
//******************************************************************************
//<--- LEE FICHEROS *.INI --->
//******************************************************************************
function GetINI(sPath: String; sName: String; sKeyName: String; sDefault: String): String;
var
  dwFile:   DWORD;
  sBuffer:  String;
  iSize:    Integer;
begin
  iSize := 0;
  dwFile := CreateFile(PChar(sPath), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  iSize := GetFileSize(dwFile, 0);

  if iSize = - 1 then exit;

  SetLength(sBuffer, iSize);
  iSize := GetPrivateProfileString(PChar(sName), PChar(sKeyName), PChar(sDefault), PChar(sBuffer), iSize, PChar(sPath));

  Result := Copy(sBuffer, 1, iSize);
end;
//******************************************************************************
//<--- ESCRIBE FICHEROS *.INI --->
//******************************************************************************
function WriteINI(sPath: String; sName: String; sKeyName: String; sValor: String): Bool;
begin
  if WritePrivateProfileString(PChar(sName), PChar(sKeyName), PChar(sValor), PChar(sPath)) = True then
    Result := True
  Else
    Result := False;
end;

end.

Saludo.
Responder Con Cita