对应的二进制内容为: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;
现在问题是读取出来的最后两个字符不对
最后两个字符应该为: ascii 29, ascii 99希望能帮我找出问题谢谢了
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;
现在问题是读取出来的最后两个字符不对
最后两个字符应该为: ascii 29, ascii 99希望能帮我找出问题谢谢了
解决方案 »
- 急求从数据库读出treeview多级目录的代码
- TDirectDrawPanel这个类是哪个控件包里的,哪有下载的呀,谢谢各位了。
- 哪位知道如何在程序运行时动态更新SeSkinEngine的界面?
- 新手请教~~~~~~~~~~~~望各位帮忙~
- win2000下如何自定义纸张大小!急。。。在线等,分可以加
- Com+注冊錯誤:Error Registering Com+ Application.Contact your Support Personnel for more information.
- 3000分!!寻找进销存管理软件完整代码,帮帮忙,各位老大!!!!!!!!!!
- Tclientsock怎么telnet服务器??
- 一个字体大小的问题
- 怎样使得STRINGGRID中的某列CELL变成下拉列表框输入?????
- dbgrid刷新问题。。
- 用delphi创建dll,dll中没有定义任何类,如何给动态创建出的控件添加事件呢?
fs:TMemoryStream;
begin
fs:=TMemoryStream.Create;
fs.LoadFromFile('C:\MyFile1.txt');
//Do something
fs.Free;
end;
for i:=0 to iBytesRead - 1 do
begin
str := str + chr(byteBuff[i]);
end;