GamerSK

15.05.2018 písomka

May 14th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.99 KB | None | 0 0
  1. //Pre viac otázok mi píšte :)
  2. //Celá zložka pre Lazarus (trošku sa buguje procedúra OnSelectCell :( ) https://mega.nz/#F!fBdUGZIa!2Zz9_KKu4zmyTPpBLKMikw
  3.  
  4. unit Unit1;
  5.  
  6. {$mode objfpc}{$H+}
  7.  
  8. interface
  9.  
  10. uses
  11. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
  12. StdCtrls, Spin;
  13.  
  14. type
  15.  
  16. { TForm1 }
  17.  
  18. TForm1 = class(TForm)
  19. Button1: TButton;
  20. Button2: TButton;
  21. Label1: TLabel;
  22. Label2: TLabel;
  23. SpinEdit1: TSpinEdit;
  24. SpinEdit2: TSpinEdit;
  25. StringGrid1: TStringGrid;
  26. StringGrid2: TStringGrid;
  27. procedure Button1Click(Sender: TObject);
  28. procedure Button2Click(Sender: TObject);
  29. procedure FormCreate(Sender: TObject);
  30. procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  31. var CanSelect: Boolean);
  32. procedure StringGrid2SelectCell(Sender: TObject; aCol, aRow: Integer;
  33. var CanSelect: Boolean);
  34. private
  35.  
  36. public
  37.  
  38. end;
  39.  
  40. var
  41. Form1: TForm1;
  42. riadok:word; //Definícia počítadla riadkov
  43. x:boolean;   //Definícia X/O
  44.  
  45. implementation
  46.  
  47. {$R *.lfm}
  48.  
  49. { TForm1 }
  50.  
  51. procedure TForm1.FormCreate(Sender: TObject);
  52. begin
  53.   //FOR DELPHI NOOBS
  54.   StringGrid1.Cells[0,0]:='1. Číslo'; //Pridá hore daný string
  55.   StringGrid1.Cells[1,0]:='2. Číslo'; //Pridá hore daný string
  56.   StringGrid1.Cells[2,0]:='Výsledok'; //Pridá hore daný string
  57.   riadok:=1; //"Vynulovanie" počítadla
  58.   x:=true; //Nastavenie pre prve X
  59. end;
  60.  
  61. procedure TForm1.Button1Click(Sender: TObject);
  62. begin
  63.   StringGrid1.Cells[0,riadok]:=inttostr(SpinEdit1.Value); //Pridá do daného riadka a prvého stĺpca VALUE z spinEditu1
  64.   StringGrid1.Cells[1,riadok]:=inttostr(SpinEdit2.Value); //Pridá do daného riadka a druhého stĺpca VALUE z spinEditu2
  65.   StringGrid1.Cells[2,riadok]:=inttostr(SpinEdit1.Value+SpinEdit2.Value); //Spočíta spinEdit1 a spinEdit2 a pridá ich do tretieho stĺpca
  66.   SpinEdit1.Value:=0; SpinEdit2.Value:=0; //Vynulovanie spinEditov1 a 2
  67.   StringGrid1.RowCount:=StringGrid1.RowCount+1; //Pridanie dalšieho riadka
  68.   inc(riadok); //Zväčšenie čísla pre riadok
  69. end;
  70.  
  71. procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  72. var CanSelect: Boolean);
  73. begin
  74.   StringGrid1.Cells[aCol,aRow]:=inputbox('Zmena údajov','Zadajte nový údaj',StringGrid1.Cells[aCol,aRow]); //Editácia po označení
  75. end;
  76.  
  77. procedure TForm1.Button2Click(Sender: TObject); //Vynulovanie pola pre piškvorky
  78. var i,j:byte;
  79. begin
  80.   for i:=0 to 2 do
  81.     begin
  82.     for j:=0 to 2 do
  83.       begin
  84.           StringGrid2.Cells[i,j]:='';
  85.         end;
  86.     end;
  87.   i:=0; j:=0;
  88. end;
  89.  
  90. procedure TForm1.StringGrid2SelectCell(Sender: TObject; aCol, aRow: Integer; //Logika piškvoriek (jednoduchá xd)
  91. var CanSelect: Boolean);
  92. begin
  93.   if X then
  94.     begin
  95.       if StringGrid2.Cells[aCol,aRow] = '' then
  96.         begin
  97.           StringGrid2.Cells[aCol,aRow]:='X';
  98.           x:=false;
  99.         end;
  100.     end
  101.   else
  102.     begin
  103.       if StringGrid2.Cells[aCol,aRow] = '' then
  104.         begin
  105.           StringGrid2.Cells[aCol,aRow]:='O';
  106.           x:=true;
  107.         end;
  108.     end;
  109. end;
  110.  
  111. end.
Advertisement
Add Comment
Please, Sign In to add comment