Advertisement
Egor_Vakar

(Delphi) lab4.1 InfoUnit

Feb 22nd, 2022
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.14 KB | None | 0 0
  1. unit InfoUnit;
  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, ClipBrd;
  8.  
  9. type
  10.   TTeamInfo = class(TForm)
  11.     MainLabel: TLabel;
  12.     NameLabel: TLabel;
  13.     PointsLabel: TLabel;
  14.     CountryLabel: TLabel;
  15.     CoachLable: TLabel;
  16.     NameEdit: TEdit;
  17.     PointsEdit: TEdit;
  18.     CountryEdit: TEdit;
  19.     CoachEdit: TEdit;
  20.     ConfirmButton: TButton;
  21.     PopupMenu: TPopupMenu;
  22.     N1: TMenuItem;
  23.     N2: TMenuItem;
  24.     N3: TMenuItem;
  25.     N4: TMenuItem;
  26.     procedure InstractionClick(Sender: TObject);
  27.     procedure CutClick(Sender: TObject);
  28.     procedure CopyClick(Sender: TObject);
  29.     procedure DeleteClick(Sender: TObject);
  30.     procedure KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  31.     procedure StrEditPress(Sender: TObject; var Key: Char);
  32.     procedure IntEditPress(Sender: TObject; var Key: Char);
  33.     procedure ButtonClick(Sender: TObject);
  34.     procedure CloseInfo(Sender: TObject; var CanClose: Boolean);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.   end;
  40.  
  41. var
  42.   TeamInfo: TTeamInfo;
  43.  
  44. implementation
  45.  
  46. {$R *.dfm}
  47.  
  48. uses lab4_1;
  49.  
  50. procedure TTeamInfo.ButtonClick(Sender: TObject);
  51. var
  52.     temp: Integer;
  53.     RowNum: String;
  54. begin
  55.     if not((NameEdit.Text = '') or (PointsEdit.Text = '') or (CountryEdit.Text = '') or (CoachEdit.Text = '')) then
  56.     begin
  57.         if (MainLAbel.Caption[Length(MainLAbel.Caption)] = 'е') then
  58.         begin
  59.             MainForm.Enabled := True;
  60.             MainForm.TeamSGrid.Enabled := True;
  61.             MainForm.TeamSGrid.RowCount := MainForm.TeamSGrid.RowCount + 1;
  62.             temp := MainForm.TeamSGrid.RowCount - 1;
  63.             MainForm.TeamSGrid.Cells[0,temp]:= NameEdit.Text;
  64.             MainForm.TeamSGrid.Cells[1,temp]:= PointsEdit.Text;
  65.             MainForm.TeamSGrid.Cells[2,temp]:= CountryEdit.Text;
  66.             MainForm.TeamSGrid.Cells[3,temp]:= CoachEdit.Text;
  67.             NameEdit.text :='';
  68.             PointsEdit.text := '';
  69.             CountryEdit.text :='';
  70.             CoachEdit.text :='';
  71.             MainForm.Height := MainForm.Height + 24;
  72.             MainForm.TeamSGrid.Height := MainForm.TeamSGrid.Height + 24;
  73.             TeamInfo.Close;
  74.             MainForm.Savetofilemenu.Enabled := True;
  75.             MainForm.TeamSGrid.Enabled := False;
  76.         end
  77.         else
  78.         begin
  79.             MainForm.Enabled := True;
  80.             MainForm.TeamSGrid.Enabled := True;
  81.             RowNum := MainLabel.Caption;
  82.             Delete(RowNum, 1, Pos('е',RowNum) + 2);
  83.             Temp := StrToInt(RowNum);
  84.             MainForm.TeamSGrid.Cells[0,temp]:= NameEdit.Text;
  85.             MainForm.TeamSGrid.Cells[1,temp]:= PointsEdit.Text;
  86.             MainForm.TeamSGrid.Cells[2,temp]:= CountryEdit.Text;
  87.             MainForm.TeamSGrid.Cells[3,temp]:= CoachEdit.Text;
  88.             NameEdit.text :='';
  89.             PointsEdit.text := '';
  90.             CountryEdit.text :='';
  91.             CoachEdit.text :='';
  92.             RowNum := MainLabel.Caption;
  93.             Delete(RowNum, Length(RowNum) - 2,3);
  94.             MainLabel.Caption := RowNum;
  95.             MainLabel.Font.Size := 11;
  96.             MainLabel.Left := 24;
  97.             TeamInfo.Close;
  98.             MainForm.Savetofilemenu.Enabled := True;
  99.             MainForm.TeamSGrid.Enabled := False;
  100.         end;
  101.     end
  102.     else
  103.         Application.MessageBox('Заполните все ячейки!', 'Ошибка', MB_ICONERROR);
  104. end;
  105.  
  106. procedure TTeamInfo.CloseInfo(Sender: TObject; var CanClose: Boolean);
  107. begin
  108.     MainForm.Enabled := True;
  109. end;
  110.  
  111. procedure TTeamInfo.CopyClick(Sender: TObject);
  112. begin
  113.     if PopupMenu.PopupComponent = NameEdit then
  114.     begin
  115.         ClipBoard.AsText := NameEdit.Text;
  116.     end;
  117.     if PopupMenu.PopupComponent = PointsEdit then
  118.     begin
  119.         ClipBoard.AsText := PointsEdit.Text;
  120.     end;
  121.     if PopupMenu.PopupComponent = CountryEdit then
  122.     begin
  123.         ClipBoard.AsText := CountryEdit.Text;
  124.     end;
  125.     if PopupMenu.PopupComponent = CoachEdit then
  126.     begin
  127.         ClipBoard.AsText := CoachEdit.Text;
  128.     end;
  129. end;
  130.  
  131. procedure TTeamInfo.CutClick(Sender: TObject);
  132. begin
  133.     if PopupMenu.PopupComponent = NameEdit then
  134.     begin
  135.         ClipBoard.AsText := NameEdit.Text;
  136.         NameEdit.Text := '';
  137.     end;
  138.     if PopupMenu.PopupComponent = PointsEdit then
  139.     begin
  140.         ClipBoard.AsText := PointsEdit.Text;
  141.         PointsEdit.Text := '';
  142.     end;
  143.     if PopupMenu.PopupComponent = CountryEdit then
  144.     begin
  145.         ClipBoard.AsText := CountryEdit.Text;
  146.         CountryEdit.Text := '';
  147.     end;
  148.     if PopupMenu.PopupComponent = CoachEdit then
  149.     begin
  150.         ClipBoard.AsText := CoachEdit.Text;
  151.         CoachEdit.Text := '';
  152.     end;
  153. end;
  154.  
  155. procedure TTeamInfo.DeleteClick(Sender: TObject);
  156. begin
  157.     if PopupMenu.PopupComponent = NameEdit then
  158.     begin
  159.         NameEdit.Text := '';
  160.     end;
  161.     if PopupMenu.PopupComponent = PointsEdit then
  162.     begin
  163.         PointsEdit.Text := '';
  164.     end;
  165.     if PopupMenu.PopupComponent = CountryEdit then
  166.     begin
  167.         CountryEdit.Text := '';
  168.     end;
  169.     if PopupMenu.PopupComponent = CoachEdit then
  170.     begin
  171.         CoachEdit.Text := '';
  172.     end;
  173. end;
  174.  
  175. procedure TTeamInfo.InstractionClick(Sender: TObject);
  176. begin
  177.     Application.MessageBox('Заполните поля, как указано в примерах','Инструкция');
  178. end;
  179.  
  180. procedure TTeamInfo.IntEditPress(Sender: TObject; var Key: Char);
  181. begin
  182.     if (TEdit(Sender).Text = '0') and (Key in ['0'..'9']) then
  183.         Key := #0;
  184.     if not(Key in ['0'..'9', #08]) then
  185.         Key := #0;
  186.     if (Length(TEdit(Sender).Text) = 2) and not(Key = #08) then
  187.         Key := #0;
  188. end;
  189.  
  190. procedure TTeamInfo.KeyDown(Sender: TObject; var Key: Word;
  191.   Shift: TShiftState);
  192. begin
  193.     TEdit(Sender).ReadOnly := (((Shift=[ssShift]) and (Key = VK_INSERT)) or (Shift=[ssCtrl]) or (Shift=[ssAlt]));
  194. end;
  195.  
  196. procedure TTeamInfo.StrEditPress(Sender: TObject; var Key: Char);
  197. begin
  198.     if (Length(TEdit(Sender).Text) = 15) and not(Key = #08) then
  199.         Key := #0;
  200. end;
  201.  
  202. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement