P
pjYan
Unregistered / Unconfirmed
GUEST, unregistred user!
用TFileStream,代码如下:
var
stream: TFileStream;
str: string;
len: Integer;
begin
str := 'test string';
len := StrLen(PChar(str));
stream := TFileStream.Create('test', fmCreate);
stream.Write(len, SizeOf(len));
stream.Write(str, len);
stream.Destroy;
stream := TFileStream.Create('test', fmOpenRead);
stream.Read(len, SizeOf(len));
SetLength(str, len);
stream.Read(str, len);
stream.Destroy;
end;
这段代码是错的,
但是要怎么改才对呢?
请大侠详细讲讲,
不才有理了!
var
stream: TFileStream;
str: string;
len: Integer;
begin
str := 'test string';
len := StrLen(PChar(str));
stream := TFileStream.Create('test', fmCreate);
stream.Write(len, SizeOf(len));
stream.Write(str, len);
stream.Destroy;
stream := TFileStream.Create('test', fmOpenRead);
stream.Read(len, SizeOf(len));
SetLength(str, len);
stream.Read(str, len);
stream.Destroy;
end;
这段代码是错的,
但是要怎么改才对呢?
请大侠详细讲讲,
不才有理了!