恒信网络科技 发表于 2012-3-24 22:43:17

求助一个关系读取的问题

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;
type
TForm1 = class(TForm)
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;
var
Form1: TForm1;
implementation
type
Lady = Record
      num: Integer;
      name: String;
      end;
Var
    VLady: File of Lady;
    h: Lady;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Var
s: String;
begin
GetDir(0,s);
AssignFile(VLady,s + '\file.dat');
if FileExists(s + '\File.dat') then
    Reset(VLady)
Else
    Rewrite(VLady);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
CloseFile(VLady);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if Edit2.Text = '' then
begin
ShowMessage('请先填写内容');
Exit
end
Else
h.num := StrToInt(Edit1.text);
h.name := Edit2.Text ;
Seek(VLady,FileSize(VLady));
Write(VLady,h);
Edit1.Text := '';
Edit2.Text := '';
ShowMessage('录入成功');
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
Var
s: Integer;
begin
//ShowMessage(IntToStr(FileSize(VLady)));
for s := 0 to FileSize(VLady) - 1 do
    begin
    Seek(Vlady,0);
    while not Eof(VLady) do
    begin
   Read(VLady,h);
   Edit1.Text := IntToStr( h.num );
   Edit2.Text := h.name ;
   end;
   end;
end;
end.


只能读出最后一个数。求高手解决下。
页: [1]
查看完整版本: 求助一个关系读取的问题