unit apprec_;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
Label3: TLabel;
Edit1: TEdit; // ìåäàëü
Button1: TButton;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
Memo1: TMemo;
StringGrid1: TStringGrid;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
// çàïèñü ôàéëà
TStud=record
Imya: string[25];
Fam: string[20];
Ot: string[20]
end;
var
Form1: TForm1;
f: file of TStud;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
var
resp : word;
begin
AssignFile(f, 'c:\ÁàçàÄàííûõ.txt');
{$I-}
Reset(f); Seek( f, FileSize(f));
{$I+}
memo1.Clear;
if IOResult = 0
then button1.enabled:=TRUE
else
begin
resp:=MessageDlg('Ôàéë áàçû äàííûõ íå íàéäåí.'+
'Ñîçäàòü íîâóþ ÁÄ?',mtInformation,[mbYes,mbNo],0);
if resp = mrYes then
begin
{$I-}
rewrite(f);
{$I+}
if IOResult = 0
then button1.enabled:=TRUE
else ShowMessage('Îøèáêà ñîçäàíèÿ ôàéëà ÁÄ.');
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Stud: TStud;
begin
with Stud do
begin
Imya:=Edit1.Text;
fam:= Edit2.Text;
Ot:=Edit3.Text;
end;
write(f, Stud);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CloseFile( f );
end;
procedure TForm1.Button2Click(Sender: TObject);
var
f:file of TStud;
rec:TStud;
st:string[80];
begin
AssignFile(f,'c:\ÁàçàÄàííûõ.txt');
{$I-}
Reset(f);
{$I-}
While not EOF(f) do
begin
read(f,rec);
st:=rec.Imya+' '+rec.Fam+' '+rec.Ot;
Memo1.Lines.Add(St);
end;
closeFile(f);
end;
end.
Мини БД, Проблема со стринггридом |