-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuFuncCompartidas.pas
61 lines (52 loc) · 1.41 KB
/
uFuncCompartidas.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
unit uFuncCompartidas;
interface
uses
System.SysUtils, Winapi.Windows, System.Classes;
Function FileToStr(mFile: String): String;
Function StrToFile(Str, Ruta: String): Boolean;
Procedure ErrorLog(Errores: TStringList; mFile: String);
implementation
uses
uUOS;
// Guarda Log en caso de errores
procedure ErrorLog(Errores: TStringList; mFile: String);
begin
Errores.SaveToFile(mFile);
end;
// Función para almacenar los bytes del fichero en una cadena
Function FileToStr(mFile: String): String;
var
hFile: THandle;
dwRet: DWORD;
iSize: DWORD;
Buff: AnsiString;
begin
hFile:= CreateFile(PChar(mFile), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
if hFile = INVALID_HANDLE_VALUE then
Exit;
iSize:= GetFileSize(hFile, nil);
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
SetLength(Buff, iSize);
ReadFile(hFile, Buff[1], iSize, dwRet, nil);
CloseHandle(hFile);
Result:= WiDeString(Buff);
end;
// Función para crear ficheros a partir de una cadena
Function StrToFile(Str, Ruta: String): Boolean;
var
hFile: THandle;
iSize: DWORD;
dwRet: DWORD;
Buff: AnsiString;
begin
Result:= False;
Buff:= AnsiString(Str);
iSize:= Length(Buff);
hFile:= CreateFile(PChar(Ruta), GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if (WriteFile(hFile, Buff[1], iSize, dwRet, nil) = True) then
Result:= True;
CloseHandle(hFile);
end;
end.