R
realism
Unregistered / Unconfirmed
GUEST, unregistred user!
Button1Click保存的文件在读的时候出错,哪位大侠能看出所在?
//窗体上加2个Button和5个Edit即可
procedure TForm1.Button1Click(Sender: TObject);
var
Stream : TFileStream;
S : String;
procedure SaveStr(var S : String);
var
Size : Integer;
begin
Size := Length(S);
Stream.Write(Size,4);
Stream.Write(S,Size);
end;
begin
Stream := TFileStream.Create('D:/ddd.txt',fmCreate or fmOpenWrite);
S := 'AAA'
SaveStr(S);
S := 'BB'
SaveStr(S);
S := 'CSA'
SaveStr(S);
S := 'DDDDD'
SaveStr(S);
S := 'EEEEE'
SaveStr(S);
Stream.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Stream : TFileStream;
S : String;
Function LoadStr : String;
var
Size : Cardinal;
P : PChar;
begin
P := nil;
Stream.Read(Size,4);
if Size>0 then
begin
P := StrAlloc(Size+1);
Stream.ReadBuffer(P,Size);
P[Size] := #0;
end;
result := P;
end;
begin
Stream := TFileStream.Create('D:/ddd.txt',fmOpenRead);
S := LoadStr
Edit1.Text := s;
S := LoadStr
Edit2.Text := s;
S := LoadStr
Edit3.Text := s;
S := LoadStr
Edit4.Text := s;
S := LoadStr
Edit5.Text := s;
Stream.Free;
end;
//窗体上加2个Button和5个Edit即可
procedure TForm1.Button1Click(Sender: TObject);
var
Stream : TFileStream;
S : String;
procedure SaveStr(var S : String);
var
Size : Integer;
begin
Size := Length(S);
Stream.Write(Size,4);
Stream.Write(S,Size);
end;
begin
Stream := TFileStream.Create('D:/ddd.txt',fmCreate or fmOpenWrite);
S := 'AAA'
SaveStr(S);
S := 'BB'
SaveStr(S);
S := 'CSA'
SaveStr(S);
S := 'DDDDD'
SaveStr(S);
S := 'EEEEE'
SaveStr(S);
Stream.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Stream : TFileStream;
S : String;
Function LoadStr : String;
var
Size : Cardinal;
P : PChar;
begin
P := nil;
Stream.Read(Size,4);
if Size>0 then
begin
P := StrAlloc(Size+1);
Stream.ReadBuffer(P,Size);
P[Size] := #0;
end;
result := P;
end;
begin
Stream := TFileStream.Create('D:/ddd.txt',fmOpenRead);
S := LoadStr
Edit1.Text := s;
S := LoadStr
Edit2.Text := s;
S := LoadStr
Edit3.Text := s;
S := LoadStr
Edit4.Text := s;
S := LoadStr
Edit5.Text := s;
Stream.Free;
end;