unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
RecordItem=record
RecordID: integer;
RecordName: string[20];
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
RecordArray:array [1..10] of RecordItem;
F:File of RecordItem;
begin
AssignFile(F, 'record.fil');
Rewrite(F);
for i:=1 to 10 do
begin
with RecordArray do
begin
RecordID:=i;
RecordName:='aaa';
end;
write(F, RecordArray);
end;
CloseFile(F);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
RecordBuff:RecordItem;
F:File of RecordItem;
begin
AssignFile(F, 'record.fil');
Reset(F);
while not eof(F) do
begin
read(F, RecordBuff);
Listbox1.Items.Add(inttostr(RecordBuff.RecordID));
Listbox1.Items.Add(RecordBuff.RecordName);
end;
CloseFile(F);
end;
end.