RSS订阅 | 匿名投稿
您的位置:网站首页 > 函数 > 正文

delphi 读取流信息

作者:admin 来源: 日期:2018/1/29 18:21:15 人气: 标签:

function ReadString(TheStream: TStream; Length: integer): string;
var
  n: longword;
  t: byte;
begin
  SetLength(result,length);
  for n:=1 to length do
  begin
    TheStream.Read(t, 1);
    result[n]:=Chr(t);
  end;
end;

function ReadNullTerminatedString(TheStream: TStream; MaxLength: longword): string;
var
  n: longword;
  TempByte: byte;
  TempChar: char;
begin
  result:='';
  for n:=1 to MaxLength do
  begin
    TheStream.Read(TempByte, 1);
    TempChar:=Chr(TempByte);
    if TempChar=#0 then
      Exit;
    result:=result+TempChar;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
PAKFile:TfileStream;
begin

if OpenDialog1.Execute  then
begin

PAKFile := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
PakFile.Position := 500;
memo1.Lines.Add(ReadString(PAKFile,255));
end;


end;

procedure TForm1.Button2Click(Sender: TObject);
var
PAKFile:TfileStream;
begin

if OpenDialog1.Execute  then
begin
PAKFile := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
//PakFile.Position :=255;
memo1.Lines.Add(ReadNullTerminatedString(PAKFile,5));
end;

end;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料