⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Label6: TLabel;
    Edit6: TEdit;
    Label7: TLabel;
    Edit7: TEdit;
    Label8: TLabel;
    Edit8: TEdit;
    Label10: TLabel;
    Edit9: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
  type
   Student= record           //定询存放学生信息的记录型
      No:String[10];
      Name: string[10];
      Age:integer;
      Sex:String[2];
      English:Real;
      Math:Real;
      Chinese:Real;
      Physics:Real;
      Aver:Real;
  end;
  StudentFile = file of Student;            //定义记录文件类型
 var
   VFStudent:StudentFile;                    //定义文件类型变量
   Stu:Student;   //定义记录型变量
   CurRecNo:Integer;      //该变量用来记录当前记录号

{$R *.dfm}
Procedure  EditClear(); //清除各文本框中的内容
begin
   Form1.Edit1.text:='';
   Form1.Edit2.text:='';
   Form1.Edit3.text:='';
   Form1.Edit4.text:='';
   Form1.Edit5.text:='';
   Form1.Edit6.text:='';
   Form1.Edit7.text:='';
   Form1.Edit8.text:='';
   Form1.Edit9.text:='';
end;
Procedure EditReadOnly();  //使各文本框只能读
begin
   Form1.Edit1.ReadOnly:=True;
  Form1.Edit2.ReadOnly:=True;
  Form1.Edit3.ReadOnly:=True;
  Form1.Edit4.ReadOnly:=True;
  Form1.Edit5.ReadOnly:=True;
  Form1.Edit6.ReadOnly:=True;
  Form1.Edit7.ReadOnly:=True;
  Form1.Edit8.ReadOnly:=True;
end;
Procedure EditReadWrite();  //使各文本框可读可写
begin
  Form1.Edit1.ReadOnly:=False;
  Form1.Edit2.ReadOnly:=False;
  Form1.Edit3.ReadOnly:=False;
  Form1.Edit4.ReadOnly:=False;
  Form1.Edit5.ReadOnly:=False;
  Form1.Edit6.ReadOnly:=False;
  Form1.Edit7.ReadOnly:=False;
  Form1.Edit8.ReadOnly:=False;
end;
procedure DispRecord(StuRec:Student);  //把记录型变量StuRec各分量的值显示出来
begin
  Form1.Edit1.Text :=StuRec.No ;
  Form1.Edit2.Text :=StuRec.Name;
  Form1.Edit3.Text :=inttostr(StuRec.Age) ;
  Form1.Edit4.Text :=StuRec.Sex;
  Form1.Edit5.Text :=floattostr(StuRec.English ) ;
  Form1.Edit6.Text :=floattostr(StuRec.Math) ;
  Form1.Edit7.Text :=floattostr(StuRec.Chinese) ;
  Form1.Edit8.Text :=floattostr(StuRec.Physics) ;
  Form1.Edit9.Text :=floattostr(StuRec.Aver) ;
end;
procedure SetRecord(Var StuRec:Student);  //把编辑框中的内容存放到记录型变量StuRec中
begin
  StuRec.No :=Form1.Edit1.Text ;
  StuRec.Name:=Form1.Edit2.Text ;
  StuRec.Age:=strtoint(Form1.Edit3.Text)  ;
  StuRec.Sex:=Form1.Edit4.Text ;
  StuRec.English:= strtofloat(Form1.Edit5.Text)  ;
  StuRec.Math:=Strtofloat(Form1.Edit6.Text)  ;
  StuRec.Chinese:=Strtofloat(Form1.Edit7.Text)  ;
  StuRec.Physics:=Strtofloat(Form1.Edit8.Text)  ;
end;

procedure TForm1.FormCreate(Sender: TObject);
  Var
    CurDir:String;
    StuFilename:String;
    M:integer;
begin
    getdir(0,CurDir);
    StuFileName:=CurDir+'\Student.dat';
    AssignFile(VFStudent,StuFileName);
    If NOT FileExists(StuFileName)  then
       ReWrite(VFStudent)
    Else
       Reset(VFStudent);
    If Eof(VFStudent) then
       EditClear
    else
       begin
          M:=filesize(VFStudent); //得到记录数
          if m=0 then  //如果文件为空
             EditClear //清除编辑框
          else
             begin
                 seek(VFStudent,M-1); //定位到最后一条记录
                 Read(VFStudent,stu);//读取最后一条记录
                 DispRecord(stu); //显示该记录的值
            end;
       end;

end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -