Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Grids, Menus, StdCtrls;
- type
- rec = record
- country: string[20];
- year1: integer;
- percent1: real;
- year2: integer;
- percent2: real;
- end;
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- Save: TMenuItem;
- Load: TMenuItem;
- Exit: TMenuItem;
- stringgrid1: TStringGrid;
- N5: TMenuItem;
- OpenForm: TMenuItem;
- DeleteRow: TMenuItem;
- StrClear: TMenuItem;
- N2: TMenuItem;
- N51: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure stringgrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
- Rect: TRect; State: TGridDrawState);
- procedure OpenFormClick(Sender: TObject);
- procedure SaveClick(Sender: TObject);
- procedure LoadClick(Sender: TObject);
- procedure StrClearClick(Sender: TObject);
- procedure DeleteRowClick(Sender: TObject);
- procedure N51Click(Sender: TObject);
- private
- { Private declarations }
- public
- end;
- var
- Form1: TForm1;
- fl: file of rec;
- i:integer;
- infcache:rec;
- implementation
- uses unit2, unit3;
- {$R *.dfm}
- procedure TForm1.DeleteRowClick(Sender: TObject);
- begin
- with stringgrid1 do begin
- if Row<>0 then
- if rowcount=Row+1 then
- rows[RowCount-1].clear else
- begin
- for i := row to rowcount - 2 do
- Rows[i]:=Rows[i+1];
- rows[RowCount-1].clear;
- end;
- RowCount:=RowCount-1;
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- with stringgrid1 do begin
- i:=1;
- colcount:=5;
- rowcount:=1;
- Cells[0,0]:='Страна';
- cells[1,0]:='Год';
- Cells[3,0]:='Год';
- rowheights[0]:=80;
- end;
- end;
- procedure TForm1.SaveClick(Sender: TObject);
- begin
- assignfile (fl, 'spisok.dat');
- rewrite(fl);
- with stringgrid1 do begin
- if RowCount>1 then
- for i := 1 to rowcount-1 do
- begin
- infcache.country:=cells[0,i];
- infcache.year1:=strtoint(cells[1,i]);
- infcache.percent1:=strtofloat(cells[2,i]);
- infcache.year2:=strtoint(cells[3,i]);
- infcache.percent2:=strtofloat(cells[4,i]);
- write(fl,infcache);
- end;
- end;
- closefile(fl);
- end;
- procedure TForm1.OpenFormClick(Sender: TObject);
- begin
- form2.left:=form1.left+form1.width;
- form2.Top:=form1.Top;
- form2.ShowModal;
- end;
- procedure TForm1.LoadClick(Sender: TObject);
- begin
- StrClearClick(mainmenu1.Items[1].find('Load'));
- assignfile(fl, 'spisok.dat');
- reset (fl);
- while not(eof(fl)) do begin
- read(fl, infcache);
- with stringgrid1 do begin
- RowCount:=RowCount+1;
- cells[0,RowCount-1]:=infcache.country;
- cells[1,RowCount-1]:=inttostr(infcache.year1);
- cells[2,RowCount-1]:=floattostr(infcache.percent1);
- cells[3,RowCount-1]:=inttostr(infcache.year2);
- cells[4,RowCount-1]:=floattostr(infcache.percent2);
- end;
- end;
- closefile(fl);
- end;
- procedure TForm1.N51Click(Sender: TObject);
- begin
- if stringgrid1.RowCount=1 then
- showmessage('Нет данных.') else
- begin
- form3.Show;
- form3.Series1.Clear;
- form3.chart1.TopAxis.Maximum:=100;
- with stringgrid1 do begin
- for i:=2 to RowCount do begin
- form3.series1.Add(strtofloat(cells[4,i-1]), cells[0,i-1], clblue);
- end;
- end;
- end;
- end;
- procedure TForm1.StrClearClick(Sender: TObject);
- begin
- if stringgrid1.RowCount>1 then begin
- for i := 1 to stringgrid1.RowCount-1 do
- StringGrid1.Rows[i].Clear;
- stringgrid1.RowCount:=1;
- end;
- end;
- procedure TForm1.stringgrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
- Rect: TRect; State: TGridDrawState);
- var Flag:cardinal;
- begin
- if arow=0 then case acol of
- 2: begin
- Flag :=DT_CENTER or DT_WORDBREAK;
- Inc(Rect.Left,3);
- Dec(Rect.Right,3);
- DrawText(
- StringGrid1.Canvas.Handle,
- PChar('Удельный вес населения, находящийся за чертой бедности'),
- length('Удельный вес населения, находящийся за чертой бедности'),Rect, flag);
- end;
- 4: begin
- Flag:= DT_CENTER or DT_WORDBREAK;
- Inc(Rect.Left,3);
- Dec(Rect.Right,3);
- DrawText(
- StringGrid1.Canvas.Handle,
- PChar('Удельный вес населения, живущего менее, чен на 1 долл. в день'),
- length('Удельный вес населения, живущего менее, чен на 1 долл. в день'),Rect,flag);
- end;
- end;
- end;
- end.
- ____________________________________________________________________________
- unit Unit2;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Grids;
- type
- TForm2 = class(TForm)
- Edit1: TEdit;
- Edit2: TEdit;
- Edit3: TEdit;
- Edit4: TEdit;
- Edit5: TEdit;
- GroupBox1: TGroupBox;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form2: TForm2;
- implementation
- uses unit1;
- {$R *.dfm}
- procedure TForm2.Button1Click(Sender: TObject);
- begin
- if not((edit1.text='') or (edit2.text='') or (edit3.text='') or (edit4.text='') or (edit5.text='')) then
- with form1.stringgrid1 do
- begin
- RowCount:=form1.StringGrid1.RowCount+1;
- Cells[0,form1.StringGrid1.RowCount-1]:=edit1.text;
- Cells[1,form1.StringGrid1.RowCount-1]:=edit2.Text;
- Cells[2,form1.StringGrid1.RowCount-1]:=edit3.text;
- Cells[3,form1.StringGrid1.RowCount-1]:=edit4.text;
- Cells[4,form1.StringGrid1.RowCount-1]:=edit5.text;
- showmessage('Данные добавлены');
- edit1.Clear; edit2.Clear; edit3.Clear; edit4.Clear; edit5.Clear;
- end else showmessage ('Введите все данные');
- end;
- end.
- ________________________________________________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement