Главная страница
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.089 c
3-1120476134
onics
2005-07-04 15:22
2005.08.14
Конвертация Excel в dbf


6-1115183884
Atrion
2005-05-04 09:18
2005.08.14
Реализовать метод POST с помощью idHTTP


4-1118771362
Unknown user
2005-06-14 21:49
2005.08.14
Утечка памяти -помогите!


3-1120677103
RusLAN_
2005-07-06 23:11
2005.08.14
Проверка правильности SQL-запроса (синтаксиса)


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