Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. unit Unit2F;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7. System.Classes, Vcl.Graphics,
  8. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
  9.  
  10. type
  11. TLab1_1 = class(TForm)
  12. Button1: TButton;
  13. MainMenu: TMainMenu;
  14. N1: TMenuItem;
  15. MenuItemAboutProgram: TMenuItem;
  16. N3: TMenuItem;
  17. PopupMenu: TPopupMenu;
  18. EditRadius: TEdit;
  19. EditY: TEdit;
  20. EditX: TEdit;
  21. Result: TLabel;
  22. Label1: TLabel;
  23. Label2: TLabel;
  24. Label3: TLabel;
  25. procedure MenuItemAboutProgramClick(Sender: TObject);
  26. procedure EditRadiusKeyPress(Sender: TObject; var Key: Char);
  27. procedure EditKeyDown(Sender: TObject; var Key: Word;
  28. Shift: TShiftState);
  29. procedure Button1Click(Sender: TObject);
  30. procedure N3Click(Sender: TObject);
  31. procedure OnCloseQuery(Sender: TObject; var CanClose: Boolean);
  32. procedure EditChange(Sender: TObject);
  33. procedure EditXKeyPress(Sender: TObject; var Key: Char);
  34. private
  35. { Private declarations }
  36. public
  37. { Public declarations }
  38. end;
  39.  
  40. var
  41. Lab1_1: TLab1_1;
  42.  
  43. implementation
  44.  
  45. {$R *.dfm}
  46.  
  47. procedure TLab1_1.EditChange(Sender: TObject); // проверка на пустотут всех трех
  48. const
  49. TypeError = 'Попытка ввода нечислового типа данных.';
  50. var
  51. WrostInput: Boolean;
  52. begin
  53. Button1.Enabled := True;
  54. with Sender as TEdit do
  55. begin
  56. WrostInput := False;
  57. try
  58. if (Length(EditRadius.Text) = 0) then
  59. Button1.Enabled := False;
  60. if (Length(EditRadius.Text) > 0) and (EditRadius.Text[1] = '-') then //todo
  61. if (EditRadius.Text[2] = '0') then
  62. begin
  63. Clear;
  64. Button1.Enabled := False;
  65. end;
  66.  
  67. if (Length(EditX.Text) = 0) then
  68. Button1.Enabled := False;
  69. if (Length(EditX.Text) = 1) and (EditX.Text[1] = '-') then
  70. Button1.Enabled := False;
  71. if (Length(EditX.Text) > 0) and (EditX.Text[1] = '-') then
  72. if (EditX.Text[2] = '0') then
  73. begin
  74. Clear;
  75. Button1.Enabled := False;
  76. end;
  77.  
  78. if (Length(EditY.Text) = 0) then
  79. Button1.Enabled := False;
  80. if (Length(EditY.Text) = 1) and (EditY.Text[1] = '-') then
  81. Button1.Enabled := False;
  82. if (Length(EditY.Text) > 0) and (EditY.Text[1] = '-') then
  83. if (EditY.Text[2] = '0') then
  84. begin
  85. Clear;
  86. Button1.Enabled := False;
  87. end;
  88. except
  89. MessageDlg(TypeError, mtError, [mbOk], 0);
  90. WrostInput := True;
  91. end;
  92. if WrostInput then
  93. begin
  94. Text := '';
  95. Button1.Enabled := False
  96. end;
  97. end;
  98. end;
  99.  
  100. procedure TLab1_1.Button1Click(Sender: TObject);
  101. const
  102. Eps = 0.001;
  103. Mess = 'Поле должно быть заполненно.';
  104. var
  105. X, Y, Radius: Integer;
  106. HypotenuseSqr: Double;
  107. IsLiesOnTheCircle: Boolean;
  108. begin
  109. Radius := StrToInt(EditRadius.Text);
  110. X := StrToInt(EditX.Text);
  111. Y := StrToInt(EditY.Text);
  112. HypotenuseSqr := sqrt(X * X + Y * Y);
  113. if Abs(HypotenuseSqr - Radius) < Eps then
  114. Result.Caption := 'Точка с заданными координатами' + #13#10 +
  115. 'лежит на окружности.'
  116. else
  117. Result.Caption := 'Точка с заданными координатами' + #13#10 +
  118. 'не лежит на окружности.';
  119. Result.Visible := True;
  120. end;
  121.  
  122. procedure TLab1_1.EditKeyDown(Sender: TObject; var Key: Word;
  123. Shift: TShiftState);
  124. var
  125. CurrentEdit: TEdit;
  126. begin
  127. CurrentEdit := TEdit(Sender);
  128. if (ssShift in Shift) then
  129. Key := 0;
  130. if ((CurrentEdit.SelStart <> Length(CurrentEdit.Text)) and
  131. ((Key = 46) or (Key = 8))) then
  132. Key := 0;
  133. end;
  134.  
  135. procedure TLab1_1.EditXKeyPress(Sender: TObject; var Key: Char);
  136. var
  137. Numerals: set of Char;
  138. begin
  139. with Sender as TEdit do
  140. begin
  141. if (Key = #13) and (Button1.Enabled) then
  142. Button1Click(Sender);
  143. if Length(Text) = 0 then
  144. Numerals := ['-', '0' .. '9', #8, #31]
  145. else
  146. Numerals := ['0' .. '9', #8, #31];
  147. if not(Key in Numerals) then
  148. Key := #0;
  149.  
  150. if (Length(Text) > 0) and (Text[1] = '0') and (Key <> #8) then
  151. Key := #0;
  152. if (Key = #8) and (Length(Text) = 2) and (Text[1] = '-') then
  153. Text := '';
  154. if (Length(Text) > 0) and (Text[1] = '-') then
  155. begin
  156. if (Length(Text) = 3) and (Key <> #8) then
  157. Key := #0;
  158. end
  159. else
  160. begin
  161. if (Length(Text) = 2) and (Key <> #8) then
  162. Key := #0;
  163. end;
  164. end;
  165. end;
  166.  
  167. procedure TLab1_1.EditRadiusKeyPress(Sender: TObject; var Key: Char);
  168. var
  169. Numerals: set of Char;
  170. begin
  171. Numerals := ['0' .. '9', #8];
  172. with Sender as TEdit do
  173. begin
  174. if (Key = #13) and (Button1.Enabled) then
  175. Button1Click(Sender);
  176. if not(Key in Numerals) then
  177. Key := #0;
  178. if (Length(Text) = 2) and (Key <> #8) then
  179. Key := #0;
  180. if (Length(Text) = 0) and (Key = '0') then
  181. Key := #0;
  182. end;
  183. end;
  184.  
  185. procedure TLab1_1.MenuItemAboutProgramClick(Sender: TObject);
  186. const
  187. ProgramTask =
  188. 'Данная программа определяет находиться ли точка* на окружности.' + #13#10
  189. + '* Диапазон значени для радиуса (0; 100).' + #13#10 +
  190. ' Для координат точки (-100; 100).';
  191. begin
  192. MessageDlg(ProgramTask, mtInformation, [mbOk], 0);
  193. end;
  194.  
  195. procedure TLab1_1.N3Click(Sender: TObject);
  196. const
  197. Programer =
  198. 'Данная программа разработанa Семенцовой Критиной, студенткой 1 курса БГУИР, факультет КСИС, специальность ПОИТ.';
  199. begin
  200. MessageDlg(Programer, mtInformation, [mbOk], 0);
  201. end;
  202.  
  203. procedure TLab1_1.OnCloseQuery(Sender: TObject; var CanClose: Boolean);
  204. const
  205. AreSure = 'Вы уверены, что хотите выйти?';
  206. var
  207. SelectedButton: Byte;
  208. begin
  209. SelectedButton := MessageDlg(AreSure, mtConfirmation, [mbYes, mbNo], 0);
  210. if SelectedButton <> mrYes then
  211. CanClose := False;
  212. end;
  213.  
  214. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement