Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.08.14;
Скачать: 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 вся ветка

Текущий архив: 2005.08.14;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.03 c
1-1122020655
Profik
2005-07-22 12:24
2005.08.14
Текст с картинками


1-1122372526
serg128
2005-07-26 14:08
2005.08.14
Как поменять цвет строки в TListBox?


14-1121840609
Ega23
2005-07-20 10:23
2005.08.14
С днем рождения! 20 июля


14-1122279431
aliced
2005-07-25 12:17
2005.08.14
class TButton not found


14-1122016086
Дмитрий999
2005-07-22 11:08
2005.08.14
Запретить обьявление экземпляра класса