Главная страница
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.025 c
1-1122461038
chili
2005-07-27 14:43
2005.08.14
Подскажите почему не работает ExtractIcon


14-1121933286
Comrade
2005-07-21 12:08
2005.08.14
Как считать пароли и логины


1-1122475280
REA
2005-07-27 18:41
2005.08.14
WebBrowser и мистика


14-1121797479
Yanis
2005-07-19 22:24
2005.08.14
Куда поставить ударение?


1-1121526080
lilo
2005-07-16 19:01
2005.08.14
TEdtit and ES_PASSWORD