Оно?
Код
var
c: array [1..6] of Byte = (11,1,00,01,110,101);
function GetFile(path: string): string;
var
Len, CntRead : Longword;
hF : THandle;
s: string;
begin
result:='';
s:='';
hF := CreateFile(PChar(path), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
if hF = INVALID_HANDLE_VALUE then
Exit;
Len := GetFileSize(hF, @Len);
SetLength(S, Len);
try
ReadFile(hF, Pointer(S)^, Len, CntRead, nil);
finally
CloseHandle(hF);
end;
result:=s;
end;
procedure WriteToFile(path, data: string);
var
hFile :THandle;
ByteWritten : cardinal;
begin
hFile:= CreateFile(PChar(path) ,GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,nil,CREATE_ALWAYS,0,0);
WriteFile(hFile, data[1], Length(data),ByteWritten, nil);
CloseHandle(hFile);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
i, r:integer;
begin
s := GetFile('text.txt');
for i:=1 to length(s) do
begin
randomize;
r := Random(6);
s[i]:= Char(c[r]);
end;
WriteToFile('text.txt', s);
end;