unit RecFile;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type Student=Record
Name:String[15];
Age :integer;
end;
StudentFile=File of Student;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Label5: TLabel;
Label6: TLabel;
Edit2: TEdit;
Button2: TButton;
OpenDialog1: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyFile:StudentFile;
Varstd:Student;
fn:string;
rc:word;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
AssignFile(MyFile,'student.rec');
Reset(MyFile);
caption:= '记录大小为:'+IntToStr(Sizeof(Varstd))
+' 共有 '+IntToStr(FileSize(MyFile))
+' 条记录';
CloseFile(MyFile);
rc:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
VarStd.Name :=Edit1.Text ;
VarStd.Age :=StrToInt(Edit2.Text);
AssignFile(MyFile,'student.rec');
Reset(MyFile);
Seek(MyFile,FileSize(MyFile));
Write(MyFile,Varstd);
CloseFile(MyFile);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if fn='' then
if OpenDialog1.Execute then
fn:=OpenDialog1.FileName
else
exit;
AssignFile(MyFile,fn);
Reset(MyFile);
if rc<FileSize(MyFile) then
begin
Seek(MyFile,rc);
Read(MyFile,VarStd);
if TButton(Sender).Name=Button2.Name then
begin
if rc<>FileSize(MyFile)-1 then
Inc(rc);
end
else
begin
if rc>0 then
Dec(rc);
end;
end;
Label4.Caption := Varstd.Name;
Label3.Caption := IntToStr(Varstd.Age);
CloseFile(MyFile);
end;end.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type Student=Record
Name:String[15];
Age :integer;
end;
StudentFile=File of Student;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Label5: TLabel;
Label6: TLabel;
Edit2: TEdit;
Button2: TButton;
OpenDialog1: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyFile:StudentFile;
Varstd:Student;
fn:string;
rc:word;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
AssignFile(MyFile,'student.rec');
Reset(MyFile);
caption:= '记录大小为:'+IntToStr(Sizeof(Varstd))
+' 共有 '+IntToStr(FileSize(MyFile))
+' 条记录';
CloseFile(MyFile);
rc:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
VarStd.Name :=Edit1.Text ;
VarStd.Age :=StrToInt(Edit2.Text);
AssignFile(MyFile,'student.rec');
Reset(MyFile);
Seek(MyFile,FileSize(MyFile));
Write(MyFile,Varstd);
CloseFile(MyFile);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if fn='' then
if OpenDialog1.Execute then
fn:=OpenDialog1.FileName
else
exit;
AssignFile(MyFile,fn);
Reset(MyFile);
if rc<FileSize(MyFile) then
begin
Seek(MyFile,rc);
Read(MyFile,VarStd);
if TButton(Sender).Name=Button2.Name then
begin
if rc<>FileSize(MyFile)-1 then
Inc(rc);
end
else
begin
if rc>0 then
Dec(rc);
end;
end;
Label4.Caption := Varstd.Name;
Label3.Caption := IntToStr(Varstd.Age);
CloseFile(MyFile);
end;end.
解决方案 »
- 设置只读后退出报错?
- 急需Delphi串口手机短信收发程序
- dbgrid的问题,大家帮忙看看
- 美女不理我了,我该怎么办?
- mdb数据库建立一对多关系后,如何保证数据完整性和一致性?
- 关于处理数据库异常的问题请教,请好心人指点
- dbgrid!简单!
- 怎么会出现执行form.create的时候调用了show事件,但真的执行.show的时候却没有?
- 请问如何把ocx控件和ocx用到的dll一块绑定发布?(web调用)
- ~~~~~~~~~~~请大家推荐object pascal书籍~~~~~~~~~~~~
- 我是用ADO连接数据库,那么我怎么对数据库进行操作呢?比如查找、删除、更新、插入。最好能不能给些源代码。。。。。。。。。。
- 如何修改一对多的数据库
这样好像用记事本就能读出来
如果是文本的话,按照自己定义的格式,或者对文本进行加密以后也会看不到的。