document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //******************************************************************************
  2. //* UNIT:         UNT_GetWriteINI
  3. //* AUTOR:        Fakedo0r
  4. //* FECHA:        14.04.2012
  5. //* CORREO:       Luvel88@gmail.com
  6. //* BLOG:         Sub-Soul.blogspot.com
  7. //* DESCRIPCION:  Permite Leer / Escribir ficheros tipo *.INI
  8. //* USO:          GetINI(\'C:\\Config.ini\', \'Opciones\', \'Puerto\', \'\');
  9. //*               WriteINI(\'C:\\Config.ini\', \'Opciones\', \'Puerto\', \'5005\');
  10. //******************************************************************************
  11. unit UNT_GetWriteINI;
  12. //******************************************************************************
  13. //DECLARACION DE LIBRERIAS / CLASES
  14. //******************************************************************************
  15. interface
  16.  
  17. uses
  18.   Winapi.Windows, System.SysUtils;
  19. //******************************************************************************
  20. //DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  21. //******************************************************************************
  22. function GetINI(sPath: String; sName: String; sKeyName: String; sDefault: String): String;
  23. function WriteINI(sPath: String; sName: String; sKeyName: String; sValor: String): Bool;
  24. //******************************************************************************
  25. implementation
  26. //******************************************************************************
  27. //<--- LEE FICHEROS *.INI --->
  28. //******************************************************************************
  29. function GetINI(sPath: String; sName: String; sKeyName: String; sDefault: String): String;
  30. var
  31.   dwFile:   DWORD;
  32.   sBuffer:  String;
  33.   iSize:    Integer;
  34. begin
  35.   iSize := 0;
  36.   dwFile := CreateFile(PChar(sPath), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  37.   iSize := GetFileSize(dwFile, 0);
  38.  
  39.   if iSize = - 1 then exit;
  40.  
  41.   SetLength(sBuffer, iSize);
  42.   iSize := GetPrivateProfileString(PChar(sName), PChar(sKeyName), PChar(sDefault), PChar(sBuffer), iSize, PChar(sPath));
  43.  
  44.   Result := Copy(sBuffer, 1, iSize);
  45. end;
  46. //******************************************************************************
  47. //<--- ESCRIBE FICHEROS *.INI --->
  48. //******************************************************************************
  49. function WriteINI(sPath: String; sName: String; sKeyName: String; sValor: String): Bool;
  50. begin
  51.   if WritePrivateProfileString(PChar(sName), PChar(sKeyName), PChar(sValor), PChar(sPath)) = True then
  52.     Result := True
  53.   Else
  54.     Result := False;
  55. end;
  56.  
  57. end.
');