Вниз
Скачать: CL | DM;

Получить содержимое файла как символы   Найти похожие ветки 

← →
InOf   (2005-07-22 10:22) [0]

Как получить содержимое не текстового файла как массив типа char?


← →
Alx2 ©   (2005-07-22 10:30) [1]

Загрузить в массив с типом элементов char


← →
Digitman ©   (2005-07-22 10:34) [2]

например, так :

var
 s: String;
 hFile: Integer;
..
SetLength(s, FileSize(..));
idFile := FileOpen(..);
try
 FileRead(hFile, PChar(s)^, Length(s));  
finally
 FileClose(hFile);
end;


← →
InOf   (2005-07-22 10:35) [3]

Спасибо


← →
InOf   (2005-07-22 11:11) [4]

тут с FileSize проблема: он не работает если файл предварительно не открыт. А так работать не хочет (external exception)

procedure DoImage(filename: string);
var
i: integer;
f: file of Byte;
s,st: String;
hFile: Integer;
idFile : integer;
begin
assign(f,filename);
reset(f);
SetLength(s, FileSize(f));
closefile(f);
idFile := FileOpen(filename,fmOpenRead);
try
  FileRead(hFile, PChar(s)^, Length(s));
finally
  FileClose(hFile);
end;
end;


← →
Anatoly Podgoretsky ©   (2005-07-22 11:25) [5]

Ты бы определился, или файлы Паскаля, или хендловые функции, зачем такой винегред?


← →
evvcom ©   (2005-07-22 11:28) [6]


> SetLength(s, FileSize(f));

А если файл гигов на 100?


← →
InOf   (2005-07-22 11:31) [7]

маленький файл


← →
Джо ©   (2005-07-22 11:35) [8]

function GetFileString (const AFileName: string): string;
var
 FS: TFileStream;
 Len: Cardinal;
begin
 FS := TFileStream.Create(AFileName,fmOpenRead);
 try
   Len := FS.Size;
   SetLength (Result,Len);
   FS.Read(Result[1],Len)
 finally
   FS.Free;
 end;
end;


← →
Джо ©   (2005-07-22 11:37) [9]

Или так


type
 TChars = array of Char;

function GetFileChars (const AFileName: string): TChars;
var
 FS: TFileStream;
 Len: Cardinal;
begin
 FS := TFileStream.Create(AFileName,fmOpenRead);
 try
   Len := FS.Size;
   SetLength (Result,Len);
   FS.Read(Result[0],Len)
 finally
   FS.Free;
 end;
end;


← →
InOf   (2005-07-22 11:53) [10]

:-) еще раз спасибо.



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.47 MB
Время: 0.029 c
1-1122025634
Destroyer
2005-07-22 13:47
2005.08.14
Проблема с вызовом переменной из другого юнита.


3-1120556071
Жук
2005-07-05 13:34
2005.08.14
Индексация поля


3-1120477465
Митяй
2005-07-04 15:44
2005.08.14
Сохранение результата запроса в таблицу


4-1118575139
Naphy
2005-06-12 15:18
2005.08.14
Параметр функции GetEnvironmentVariable...


1-1122014723
Valera
2005-07-22 10:45
2005.08.14
Замена в Run-Time




   Наверх