unit Unit1;

interface

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

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
MainMenu1: TMainMenu;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
df1: TMenuItem;
Cvfn1: TMenuItem;
Open1: TMenuItem;
Button1: TButton;
N1: TMenuItem;
procedure N1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Cvfn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
type avto=record
model:string[8];
year:integer;
price:integer;
end;
var sf:string; tabmodified:boolean;

procedure tabclear;
var i,j:integer;
begin
with form1.StringGrid1 do
for j:=0 to rowcount do
for i:=0 to colcount do
cells[i,j]:='';
end;


procedure tabforfile;
var i:integer;
begin
with form1.StringGrid1 do begin
colcount:=3;
rowcount:=5;
fixedcols:=0;
fixedrows:=1;
colwidths[0]:=50;
colwidths[1]:=50;
colwidths[2]:=50;
cells[0,0]:='Model';
cells[1,0]:='Year';
cells[2,0]:='Price';

width:=25;
for i:=0 to 3 do
width:=width+colwidths[i];
end;

with form1.StringGrid2 do begin
colcount:=3;
rowcount:=5;
fixedcols:=0;
fixedrows:=1;
colwidths[0]:=50;
colwidths[1]:=50;
colwidths[2]:=50;
cells[0,0]:='Model';
cells[1,0]:='Year';
cells[2,0]:='Price';

width:=25;
for i:=0 to 3 do
width:=width+colwidths[i];
end;
end;



procedure savetofileofavto;
var f:file of avto; z:avto;i:integer;
begin
assignfile(f,sf);
rewrite(f);
i:=1;
with form1.StringGrid1 do
with z do
while i if cells[0,i]<>'' then begin
model:=cells[0,i];
year:=strtoint(cells[1,i]);
price:=strtoint(cells[2,i]);
write(f,z);
end;
i:=i+1;

end;
closefile(f);
end;

procedure loadfromfileofavto;
var f:file of avto;
z:avto;i:integer;
begin
assignfile(f,sf);
reset(f);
i:=1;
tabclear;
while not eof(f) do
with form1.StringGrid1 do
with z do begin
read(f,z);
cells[0,i]:=Model;
cells[1,i]:=inttostr(year);
cells[2,i]:=inttostr(price);
i:=i+1;
end;
closefile(f);

end;

procedure TForm1.Button1Click(Sender: TObject);
var i,j,n:integer; f:file of avto;z:avto;
begin
n:=strtoint(inputbox('as','vvedite god',''));
assignfile(f,sf);
reset(f);
i:=1;
while not eof(f) do
with form1.StringGrid2 do
with z do begin
read(f,z);
if year>n then begin
cells[0,i]:=Model;
cells[1,i]:=inttostr(year);
cells[2,i]:=inttostr(price);
end;
i:=i+1;
end;
closefile(f);
end;

procedure TForm1.Cvfn1Click(Sender: TObject);
begin
if savedialog1.execute then begin
sf:=savedialog1.FileName;
savetofileofavto;
form1.Caption:='Form1'+sf;
tabmodified:=false;

end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
tabmodified:=false;
stringgrid1.Options:= stringgrid1.options+[goEditing];
tabforfile;
sf:='';
end;

procedure TForm1.N1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.Open1Click(Sender: TObject);
begin
if tabmodified then
case messagedlg('текст был изменён'+#13+'сохранить?',mtConfirmation,[mbYes,mbNo,mbCancel],0)
of
mrYes:Cvfn1click(self);
mrNo:;
mrCancel:exit;
end;
if opendialog1.execute then
begin
sf:=opendialog1.filename;
loadfromfileofavto;
form1.Caption:='Form1'+sf;
tabmodified:=false;
end;
end;

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
begin
tabmodified:=true;
end;


end.





Чтобы не видеть здесь видео-рекламу достаточно стать зарегистрированным пользователем.
Чтобы не видеть никакую рекламу на сайте, нужно стать VIP-пользователем.
Это можно сделать совершенно бесплатно. Читайте подробности тут.