안녕 하세요?
BacTeria 박종민 입니다.
델파이에서 바이너리 파일을 액세스 하기 위한 함수로는
FileOpen, FileClose, FileRead, FileWrite, FileSeek 등의 함수가 있습니다.
델파이의 도움말에 자세히 설명 되어 있으니 참고 하세요~
예제를 직접 올리지 못해 죄송합니다.
이만... 박종민...
--------------------------------------------------------------------------------
{ 아래에 있는 내용은 델파이의 도움말 원문 입니다 }
FileOpen, FileSeek, FileRead Example
====================================
The following example uses a button, a string grid, and an Open dialog box on a
form. When the button is clicked, the user is prompted for a filename. When the
user clicks OK, the specified file is opened, read into a buffer, and closed. Th
en the buffer is displayed in two columns of the string grid. The first column c
ontains the character values in the buffer. The second column contains the numer
ic values of the characters in the buffer.
procedure TForm1.Button1Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: PChar;
i: Integer
begin
if OpenDialog1.Execute then
begin
try
iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead = FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle);
for i := 0 to iBytesRead-1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[1,i+1] := Buffer[i];
StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
end;
finally
FreeMem(Buffer);
end;
end;
end;
|