小甲鱼Delphi教程37课《读写修改记录型文件》源码
说明:本程序用delphi10.4重写编写
一、最后效果
二、源码
1 unit Unit1; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; 8 9 type 10 TForm1 = class(TForm) 11 LabeledEdit1: TLabeledEdit; 12 LabeledEdit2: TLabeledEdit; 13 Button1: TButton; 14 Button2: TButton; 15 procedure FormCreate(Sender: TObject); 16 procedure FormClose(Sender: TObject; var Action: TCloseAction); 17 procedure Button1Click(Sender: TObject); 18 procedure Button2Click(Sender: TObject); 19 private 20 { Private declarations } 21 public 22 { Public declarations } 23 end; 24 25 var 26 Form1: TForm1; 27 28 implementation 29 type 30 Lady=record 31 num: Byte; 32 name: string[10]; 33 end; 34 var 35 VFlady: file of Lady; 36 v1:Lady; 37 {$R *.dfm} 38 39 procedure TForm1.Button1Click(Sender: TObject); 40 begin 41 v1.num:=StrToInt(LabeledEdit1.text); 42 v1.name:=LabeledEdit2.Text; 43 Seek(VFlady,filesize(vflady)); 44 write(VFlady,v1); 45 ShowMessage(IntToStr(FileSize(VFlady))); 46 end; 47 48 procedure TForm1.Button2Click(Sender: TObject); 49 var 50 n:Integer; 51 begin 52 n:=StrToInt(inputbox('提醒!','输入需要修改的编号','1')); 53 Seek(VFlady,n-1); 54 read(VFlady,v1); 55 v1.name:=inputbox('提醒!','输入需要修改的编号','姓名'); 56 Seek(VFlady,n-1); 57 write(vflady,v1); 58 59 60 end; 61 62 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); 63 begin 64 CloseFile(VFlady); 65 end; 66 67 procedure TForm1.FormCreate(Sender: TObject); 68 var 69 curdir:string; 70 begin 71 GetDir(0,curdir); 72 AssignFile(VFlady,curdir+'\wocao.dat'); 73 if FileExists(curdir+'\wocao.dat') then 74 Reset(VFlady) 75 else 76 Rewrite(vflady); 77 78 79 end; 80 81 end.
三、源码下载
https://download.csdn.net/download/yanglu_115/88550299