16,748
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.btn3Click(Sender: TObject);
var
iFileHandle, iFileLength, iBytesRead : Integer;
byteBuff : array of Byte;
byteBuffTemp : array of Byte;
aLeng, sIndex : Integer;
i : Integer;
str, stra, strb : string;
begin
iFileHandle := FileOpen('C://myFile1.txt', fmOpenRead);
iFileLength := FileSeek(iFileHandle, 0, 2);
ShowMessage('iFileLength = ' + IntToStr(iFileLength));
FileSeek(iFileHandle, 0, 0);
SetLength(byteBuff, iFileLength);
iBytesRead := FileRead(iFileHandle, byteBuff[0], iFileLength);
FileClose(iFileHandle);
sIndex := 0;
str := '';
aLeng := 5;
SetLength(str, aLeng);
Move(byteBuff[sIndex], str[1], aLeng);
ShowMessage('str=' + str);
sIndex := aLeng;
str := '';
aLeng := 10;
SetLength(str, aLeng);
Move(byteBuff[sIndex], str[1], aLeng);
ShowMessage('str=' + str);
sIndex := aLeng;
str := '';
aLeng := 1;
SetLength(str, aLeng);
Move(byteBuff[sIndex], str[1], aLeng);
ShowMessage('str=' + str);
sIndex := aLeng;
str := '';
aLeng := 1;
SetLength(str, aLeng);
Move(byteBuff[sIndex], str[1], aLeng);
ShowMessage('str=' + str);
str := '';
for i:=0 to iBytesRead do
begin
str := str + chr(byteBuff[i]);
end;
ShowMessage(str);
byteBuff := nil;
end;
str := '';
for i:=0 to iBytesRead - 1 do
begin
str := str + chr(byteBuff[i]);
end;