Akaleaf

RadioButtons

Dec 4th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.68 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   Grids, StdCtrls, Spin;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     Button3: TButton;
  19.     Edit1: TEdit;
  20.     GroupBox1: TGroupBox;
  21.     GroupBox2: TGroupBox;
  22.     GroupBox3: TGroupBox;
  23.     Label1: TLabel;
  24.     Label2: TLabel;
  25.     Label3: TLabel;
  26.     Panel1: TPanel;
  27.     RadioButton1: TRadioButton;
  28.     RadioButton2: TRadioButton;
  29.     RadioButton3: TRadioButton;
  30.     RadioGroup1: TRadioGroup;
  31.     SpinEdit1: TSpinEdit;
  32.     SpinEdit2: TSpinEdit;
  33.     SpinEdit3: TSpinEdit;
  34.     SpinEdit4: TSpinEdit;
  35.     StringGrid1: TStringGrid;
  36.     procedure Button1Click(Sender: TObject);
  37.     procedure Button2Click(Sender: TObject);
  38.     procedure Button3Click(Sender: TObject);
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure SpinEdit3Change(Sender: TObject);
  41.   private
  42.     { private declarations }
  43.   public
  44.     { public declarations }
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51. uses Unit2;
  52.  
  53. {$R *.lfm}
  54.  
  55. { TForm1 }
  56.  
  57. procedure TForm1.FormCreate(Sender: TObject);
  58. begin
  59.   SpinEdit1.Value := StringGrid1.RowCount;
  60.   SpinEdit2.Value := StringGrid1.ColCount;
  61. end;
  62.  
  63. procedure TForm1.SpinEdit3Change(Sender: TObject);
  64. begin
  65.  
  66. end;
  67.  
  68. procedure TForm1.Button1Click(Sender: TObject);
  69. begin
  70.   StringGrid1.ColCount := SpinEdit2.Value;
  71.   StringGrid1.RowCount := SpinEdit1.Value;
  72. end;
  73.  
  74. procedure TForm1.Button2Click(Sender: TObject);
  75. var i, ii: integer;
  76. begin
  77.   Randomize;
  78.   if (SpinEdit4.Value < SpinEdit3.Value) then
  79.   ShowMessage('Error: wrong range') else
  80.     begin
  81.       for i := 0 to StringGrid1.ColCount - 1 do
  82.       begin
  83.         for ii := 0 to StringGrid1.RowCount - 1 do
  84.         begin
  85.           StringGrid1.Cells[i, ii] := IntToStr(Random(SpinEdit4.Value - SpinEdit3.Value + 1) + SpinEdit3.Value);
  86.         end;
  87.       end;
  88.     end;
  89. end;
  90.  
  91. procedure TForm1.Button3Click(Sender: TObject);
  92. var i, ii, iii: integer;
  93.   isFinded : boolean;
  94.   location : String;
  95. begin
  96.   if Edit1.Text = '' then
  97.   begin
  98.     ShowMessage('Error: enter the desired number')
  99.   end else
  100.   begin
  101.     isFinded := false;
  102.     if RadioButton1.Checked = true then
  103.     begin
  104.       for i := 0 to StringGrid1.RowCount - 1 do
  105.       begin
  106.         for ii := 0 to StringGrid1.ColCount - 1 do
  107.         begin
  108.           if (StringGrid1.Cells[ii, i] = (Edit1.Text)) then
  109.           begin
  110.             isFinded := true;
  111.             Label3.Caption := ('Location: ' + IntToStr(i + 1) + ' ' + IntToStr(ii + 1));
  112.             break;
  113.           end;
  114.         end;
  115.         if isFinded then break;
  116.       end;
  117.     end;
  118.     if RadioButton2.Checked = true then
  119.     begin
  120.       for i := StringGrid1.RowCount - 1 downto 0 do
  121.       begin
  122.         for ii := StringGrid1.ColCount - 1 downto 0 do
  123.         begin
  124.           if (StringGrid1.Cells[ii, i] = Edit1.Text) tuhen
  125.           begin
  126.             isFinded := true;
  127.             Label3.Caption := ('Location: ' + IntToStr(i + 1) + ' ' + IntToStr(ii + 1));
  128.             break;
  129.           end;
  130.         end;
  131.         if isFinded then break;
  132.       end;
  133.     end;
  134.     iii := 0;
  135.     if RadioButton3.Checked = true then
  136.     begin
  137.       Form2.Show;
  138.       Form2.Visible:=false;
  139.       for i := 0 to StringGrid1.RowCount - 1 do
  140.       begin
  141.         for ii := 0 to StringGrid1.ColCount - 1 do
  142.         begin
  143.           if (StringGrid1.Cells[ii, i] = (Edit1.Text)) then
  144.           begin
  145.             Form2.Memo1.Lines[iii] := 'Location: ' + IntToStr(i + 1) + ' ' + IntToStr(ii + 1);
  146.             iii += 1;
  147.           end;
  148.         end;
  149.       end;
  150.       Form2.ShowModal;
  151.     end;
  152.   end;
  153. end;
  154.  
  155. end.
Advertisement
Add Comment
Please, Sign In to add comment