Advertisement
believe_me

Untitled

Apr 5th, 2022
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.16 KB | None | 0 0
  1. unit MainUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls,
  8.   Vcl.Samples.Spin;
  9.  
  10. type
  11.   TMain = class(TForm)
  12.     MainMenu: TMainMenu;
  13.     InstructionMenu: TMenuItem;
  14.     DeveloperMenu: TMenuItem;
  15.     SizeSpinEdit: TSpinEdit;
  16.     Label1: TLabel;
  17.     BuildButton: TButton;
  18.     procedure DeveloperMenuClick(Sender: TObject);
  19.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  20.     procedure InstructionMenuClick(Sender: TObject);
  21.     procedure SizeSpinEditChange(Sender: TObject);
  22.     procedure SizeSpinEditKeyPress(Sender: TObject; var Key: Char);
  23.     procedure BuildButtonClick(Sender: TObject);
  24.   private
  25.     { Private declarations }
  26.   public
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   Main: TMain;
  32.   Size: integer;
  33.  
  34. implementation
  35.  
  36. {$R *.dfm}
  37.  
  38. Uses
  39.     MagicBoxUnit, ShowSquareUnit;
  40.  
  41.  
  42. procedure TMain.BuildButtonClick(Sender: TObject);
  43.  
  44. var
  45.     Sum, Size: integer;
  46.  
  47.  
  48. begin
  49.     if (SizeSpinEdit.Text = '') then
  50.         MessageDlg('Введите порядок квадрата.', mtError, [mbOk], 0)
  51.     else if (strToInt(SizeSpinEdit.Text) > 24) or (strToInt(SizeSpinEdit.Text) < 4) then
  52.         MessageDlg('Порядок должен быть в диапазон 4..24.', mtError, [mbOk], 0)
  53.     else if ((strToInt(SizeSpinEdit.Text) mod 4) <> 0) then
  54.         MessageDlg('Порядок должен быть кратным 4.', mtError, [mbOk], 0)
  55.     else
  56.     begin
  57.         ShowForm.Show;
  58.     end;
  59.  
  60. end;
  61.  
  62. procedure TMain.DeveloperMenuClick(Sender: TObject);
  63. begin
  64.     Application.MessageBox('Студент группы 151002 Раводин Александр.', 'О разработчике');
  65. end;
  66.  
  67.  
  68. procedure TMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  69. var
  70.     lpCaption, lpText: PChar;
  71.     Tip: Integer;
  72.     WND: HWND;
  73.  
  74. begin
  75.     WND := Main.Handle;
  76.     lpCaption := 'Выход';
  77.     lpText := 'Вы уверены, что хотите выйти?';
  78.     Tip := MB_YESNO + MB_ICONINFORMATION + MB_DEFBUTTON2;
  79.     case MessageBox(WND, lpText, lpCaption, Tip) of
  80.         IDYES : CanClose := True;
  81.         IDNO : CanClose := False;
  82.     end;
  83. end;
  84.  
  85.  
  86. procedure TMain.InstructionMenuClick(Sender: TObject);
  87.  
  88. Var
  89.     InstructionMenu: TForm;
  90.     Instruction: string;
  91.  
  92. begin
  93.     Instruction := 'Данная программа строит магический квадрат чётно-чётного порядка латинским способом.';
  94.     InstructionMenu := CreateMessageDialog(Instruction, mtInformation, [mbOk], mbOK);
  95.     InstructionMenu.ShowModal;
  96.     InstructionMenu.Free;
  97. end;
  98.  
  99.  
  100. procedure TMain.SizeSpinEditChange(Sender: TObject);
  101. begin
  102.     if SizeSpinEdit.Text <> '' then
  103.         BuildButton.Enabled := true
  104.     else
  105.         BuildButton.Enabled := false;
  106. end;
  107.  
  108.  
  109. procedure TMain.SizeSpinEditKeyPress(Sender: TObject; var Key: Char);
  110.  
  111. begin
  112.     if (SizeSpinEdit.Value <> 0) and (Key = #13) then
  113.         BuildButtonClick(Sender);
  114.     if (SizeSpinEdit.Text = '0') and (Key <> #08) then
  115.         Key := #0;
  116. end;
  117.  
  118.  
  119.  
  120. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement