Advertisement
helos3

Praktika

Jul 10th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, Grids, Menus, StdCtrls;
  8.  
  9. type
  10. rec = record
  11. country: string[20];
  12. year1: integer;
  13. percent1: real;
  14. year2: integer;
  15. percent2: real;
  16. end;
  17. TForm1 = class(TForm)
  18. MainMenu1: TMainMenu;
  19. N1: TMenuItem;
  20. Save: TMenuItem;
  21. Load: TMenuItem;
  22. Exit: TMenuItem;
  23. stringgrid1: TStringGrid;
  24. N5: TMenuItem;
  25. OpenForm: TMenuItem;
  26. DeleteRow: TMenuItem;
  27. StrClear: TMenuItem;
  28. N2: TMenuItem;
  29. N51: TMenuItem;
  30. procedure FormCreate(Sender: TObject);
  31. procedure stringgrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  32. Rect: TRect; State: TGridDrawState);
  33. procedure OpenFormClick(Sender: TObject);
  34. procedure SaveClick(Sender: TObject);
  35. procedure LoadClick(Sender: TObject);
  36. procedure StrClearClick(Sender: TObject);
  37. procedure DeleteRowClick(Sender: TObject);
  38. procedure N51Click(Sender: TObject);
  39.  
  40. private
  41. { Private declarations }
  42. public
  43.  
  44. end;
  45.  
  46. var
  47. Form1: TForm1;
  48. fl: file of rec;
  49. i:integer;
  50. infcache:rec;
  51.  
  52. implementation
  53. uses unit2, unit3;
  54.  
  55.  
  56. {$R *.dfm}
  57.  
  58.  
  59.  
  60. procedure TForm1.DeleteRowClick(Sender: TObject);
  61. begin
  62. with stringgrid1 do begin
  63. if Row<>0 then
  64. if rowcount=Row+1 then
  65. rows[RowCount-1].clear else
  66. begin
  67. for i := row to rowcount - 2 do
  68. Rows[i]:=Rows[i+1];
  69. rows[RowCount-1].clear;
  70. end;
  71. RowCount:=RowCount-1;
  72. end;
  73. end;
  74.  
  75. procedure TForm1.FormCreate(Sender: TObject);
  76. begin
  77. with stringgrid1 do begin
  78. i:=1;
  79. colcount:=5;
  80. rowcount:=1;
  81. Cells[0,0]:='Страна';
  82. cells[1,0]:='Год';
  83. Cells[3,0]:='Год';
  84. rowheights[0]:=80;
  85. end;
  86. end;
  87.  
  88. procedure TForm1.SaveClick(Sender: TObject);
  89. begin
  90. assignfile (fl, 'spisok.dat');
  91. rewrite(fl);
  92. with stringgrid1 do begin
  93. if RowCount>1 then
  94. for i := 1 to rowcount-1 do
  95. begin
  96. infcache.country:=cells[0,i];
  97. infcache.year1:=strtoint(cells[1,i]);
  98. infcache.percent1:=strtofloat(cells[2,i]);
  99. infcache.year2:=strtoint(cells[3,i]);
  100. infcache.percent2:=strtofloat(cells[4,i]);
  101. write(fl,infcache);
  102. end;
  103. end;
  104. closefile(fl);
  105. end;
  106.  
  107. procedure TForm1.OpenFormClick(Sender: TObject);
  108. begin
  109. form2.left:=form1.left+form1.width;
  110. form2.Top:=form1.Top;
  111. form2.ShowModal;
  112. end;
  113.  
  114. procedure TForm1.LoadClick(Sender: TObject);
  115. begin
  116. StrClearClick(mainmenu1.Items[1].find('Load'));
  117. assignfile(fl, 'spisok.dat');
  118. reset (fl);
  119. while not(eof(fl)) do begin
  120. read(fl, infcache);
  121. with stringgrid1 do begin
  122. RowCount:=RowCount+1;
  123. cells[0,RowCount-1]:=infcache.country;
  124. cells[1,RowCount-1]:=inttostr(infcache.year1);
  125. cells[2,RowCount-1]:=floattostr(infcache.percent1);
  126. cells[3,RowCount-1]:=inttostr(infcache.year2);
  127. cells[4,RowCount-1]:=floattostr(infcache.percent2);
  128. end;
  129. end;
  130. closefile(fl);
  131. end;
  132.  
  133.  
  134. procedure TForm1.N51Click(Sender: TObject);
  135. begin
  136. if stringgrid1.RowCount=1 then
  137. showmessage('Нет данных.') else
  138. begin
  139. form3.Show;
  140. form3.Series1.Clear;
  141. form3.chart1.TopAxis.Maximum:=100;
  142. with stringgrid1 do begin
  143. for i:=2 to RowCount do begin
  144. form3.series1.Add(strtofloat(cells[4,i-1]), cells[0,i-1], clblue);
  145. end;
  146. end;
  147. end;
  148. end;
  149.  
  150. procedure TForm1.StrClearClick(Sender: TObject);
  151. begin
  152. if stringgrid1.RowCount>1 then begin
  153. for i := 1 to stringgrid1.RowCount-1 do
  154. StringGrid1.Rows[i].Clear;
  155. stringgrid1.RowCount:=1;
  156. end;
  157. end;
  158.  
  159. procedure TForm1.stringgrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  160. Rect: TRect; State: TGridDrawState);
  161. var Flag:cardinal;
  162. begin
  163. if arow=0 then case acol of
  164. 2: begin
  165. Flag :=DT_CENTER or DT_WORDBREAK;
  166. Inc(Rect.Left,3);
  167. Dec(Rect.Right,3);
  168. DrawText(
  169. StringGrid1.Canvas.Handle,
  170. PChar('Удельный вес населения, находящийся за чертой бедности'),
  171. length('Удельный вес населения, находящийся за чертой бедности'),Rect, flag);
  172. end;
  173. 4: begin
  174. Flag:= DT_CENTER or DT_WORDBREAK;
  175. Inc(Rect.Left,3);
  176. Dec(Rect.Right,3);
  177. DrawText(
  178. StringGrid1.Canvas.Handle,
  179. PChar('Удельный вес населения, живущего менее, чен на 1 долл. в день'),
  180. length('Удельный вес населения, живущего менее, чен на 1 долл. в день'),Rect,flag);
  181. end;
  182. end;
  183. end;
  184.  
  185. end.
  186.  
  187. ____________________________________________________________________________
  188. unit Unit2;
  189.  
  190. interface
  191.  
  192. uses
  193. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  194. Dialogs, StdCtrls, Grids;
  195.  
  196. type
  197. TForm2 = class(TForm)
  198. Edit1: TEdit;
  199. Edit2: TEdit;
  200. Edit3: TEdit;
  201. Edit4: TEdit;
  202. Edit5: TEdit;
  203. GroupBox1: TGroupBox;
  204. Label1: TLabel;
  205. Label2: TLabel;
  206. Label3: TLabel;
  207. Label4: TLabel;
  208. Label5: TLabel;
  209. Button1: TButton;
  210. procedure Button1Click(Sender: TObject);
  211. private
  212. { Private declarations }
  213. public
  214. { Public declarations }
  215. end;
  216.  
  217. var
  218. Form2: TForm2;
  219.  
  220.  
  221. implementation
  222. uses unit1;
  223.  
  224. {$R *.dfm}
  225.  
  226. procedure TForm2.Button1Click(Sender: TObject);
  227. begin
  228. if not((edit1.text='') or (edit2.text='') or (edit3.text='') or (edit4.text='') or (edit5.text='')) then
  229. with form1.stringgrid1 do
  230. begin
  231. RowCount:=form1.StringGrid1.RowCount+1;
  232. Cells[0,form1.StringGrid1.RowCount-1]:=edit1.text;
  233. Cells[1,form1.StringGrid1.RowCount-1]:=edit2.Text;
  234. Cells[2,form1.StringGrid1.RowCount-1]:=edit3.text;
  235. Cells[3,form1.StringGrid1.RowCount-1]:=edit4.text;
  236. Cells[4,form1.StringGrid1.RowCount-1]:=edit5.text;
  237. showmessage('Данные добавлены');
  238. edit1.Clear; edit2.Clear; edit3.Clear; edit4.Clear; edit5.Clear;
  239. end else showmessage ('Введите все данные');
  240. end;
  241. end.
  242. ________________________________________________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement