N
nanshan
Unregistered / Unconfirmed
GUEST, unregistred user!
function ReadStreamText(var FStream: TFileStream): string;var AText: pchar; nb: integer;begin FStream.Read(nb, SizeOf(nb)); FStream.Read(AText^, nb); SetLength(Result, nb); Move(AText^, Result[1], nb);// FreeMemory(AText);end;procedure TForm1.Button2Click(Sender: TObject);var FileItem: TFileItem; mp: TFileStream; Str: string[255]; S: string;begin mp := TFileStream.Create('e:/1.txt', fmOpenRead); FillChar(FileItem, SizeOf(TFileItem), 0); mp.Read(FileItem, SizeOf(TFileItem)); S := ReadStreamText(mp); //Memo2.Text := S; showmessage(s); //显示正常,关闭后出错 //mp.Read(Str, 6); // Form1.Caption := Str; mp.Free;end;可以读出字符,但会出错,我对文件流读取不太熟悉,请各位赐教