Paintbox already starts routine when Form1.show is enabled lazarus / 31-LCL ---------------------------------------------------------------------- JVlaanderen · 2022-03-18 15:47 Hi! So I'm quite new to Lazrus, and right now I'm trying to make kind of a QR-code with a paintbox in Lazarus. So my program starts with an 'menu-screen' (Form 2), and when Button1 is clicked, you wille be redirected to Form1, where the paintbox is with some spinedit's which indicate the width and height of the paintbox etc. Now when I click Button1 in Form 2, I get redirected to Form1, which is good, but the program directly starts all my procedures, so the paintbox will already paint before I can even have the chance to fill in the height and width of my paintbox. Here's my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Unit5,  Spin, Menus, math, Unit3; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    ColorButton1: TColorButton;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    MainMenu1: TMainMenu;    MenuItem1: TMenuItem;    MenuItem2: TMenuItem;    MenuItem3: TMenuItem;    MenuItem4: TMenuItem;    MenuItem5: TMenuItem;    MenuItem6: TMenuItem;    MenuItem7: TMenuItem;    PaintBox1: TPaintBox;    SpinEdit1: TSpinEdit;    SpinEdit2: TSpinEdit;    SpinEdit3: TSpinEdit;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure Initiate;    procedure MenuItem3Click(Sender: TObject);    procedure MenuItem4Click(Sender: TObject);    procedure MenuItem5Click(Sender: TObject);    procedure MenuItem7Click(Sender: TObject);    procedure Draw;    procedure Nextround;    procedure Drawempty;  private   public   end; var  Form1: TForm1;  startchance : integer;  newcel,  cel : array[1..100, 1..100] of integer;  sizeX, sizeY:integer;  x,y,number : integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.nextround;var dx,dy,x,y,numbers : integer;Begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      aantal:=0;      for dx:=-1 to 1 do begin        for dy:=-1 to 1 do begin          numbers:=numbers+cel[x+dx,y+dy];          end;        end;      numbers:=numbers-cel[x,y];       if ((cel[x,y]=1) and (aantal>4)) or ((cel[x,y]=0) and (aantal>5)) then begin        newcel[x,y]:=1;        end;       end;    end;   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      cel[x,y]:=newcel[x,y];      end;    end; end; procedure Tform1.draw;var x,y : integer;begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      if cel[x,y]=1 then begin        paintbox1.Canvas.Brush.color:=colorbutton1.buttoncolor;        end    else begin        paintbox1.Canvas.brush.color:=clWhite;        end;      paintbox1.canvas.FillRect(20+x*5,20+y*5,25+x*5,25+y*5);      end;    end; end; procedure Tform1.drawempty;var x,y : integer;begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      if cel[x,y]=1 then begin        paintbox1.Canvas.Brush.color:=clWhite;      end      else begin        paintbox1.Canvas.brush.color:=clWhite;        end;      paintbox1.canvas.FillRect(20+x*5,20+y*5,25+x*5,25+y*5);      end;    end; end; procedure Tform1.initiate;var x,y,number : integer;begin  sizeX:=75;  sizeY:=75;  startingchance := SpinEdit1.value;   Paintbox1.Width := SpinEdit2.Value;  Paintbox1.Height := SpinEdit3.Value;   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      getal:=randomrange(0,100);      if numberPublish Project... menu to give a zipped file of your sources which you can attach to a forum post using the    +Attachments and other options link ---------------------------------------------------------------------- zeljko · 2022-03-18 20:16 Quote from: JVlaanderen on March 18, 2022, 04:47:11 pmHi! So I'm quite new to Lazrus, and right now I'm trying to make kind of a QR-code with a paintbox in Lazarus. So my program starts with an 'menu-screen' (Form 2), and when Button1 is clicked, you wille be redirected to Form1, where the paintbox is with some spinedit's which indicate the width and height of the paintbox etc. Now when I click Button1 in Form 2, I get redirected to Form1, which is good, but the program directly starts all my procedures, so the paintbox will already paint before I can even have the chance to fill in the height and width of my paintbox. Here's my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Unit5,  Spin, Menus, math, Unit3; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    ColorButton1: TColorButton;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    MainMenu1: TMainMenu;    MenuItem1: TMenuItem;    MenuItem2: TMenuItem;    MenuItem3: TMenuItem;    MenuItem4: TMenuItem;    MenuItem5: TMenuItem;    MenuItem6: TMenuItem;    MenuItem7: TMenuItem;    PaintBox1: TPaintBox;    SpinEdit1: TSpinEdit;    SpinEdit2: TSpinEdit;    SpinEdit3: TSpinEdit;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure Initiate;    procedure MenuItem3Click(Sender: TObject);    procedure MenuItem4Click(Sender: TObject);    procedure MenuItem5Click(Sender: TObject);    procedure MenuItem7Click(Sender: TObject);    procedure Draw;    procedure Nextround;    procedure Drawempty;  private   public   end; var  Form1: TForm1;  startchance : integer;  newcel,  cel : array[1..100, 1..100] of integer;  sizeX, sizeY:integer;  x,y,number : integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.nextround;var dx,dy,x,y,numbers : integer;Begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      aantal:=0;      for dx:=-1 to 1 do begin        for dy:=-1 to 1 do begin          numbers:=numbers+cel[x+dx,y+dy];          end;        end;      numbers:=numbers-cel[x,y];       if ((cel[x,y]=1) and (aantal>4)) or ((cel[x,y]=0) and (aantal>5)) then begin        newcel[x,y]:=1;        end;       end;    end;   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      cel[x,y]:=newcel[x,y];      end;    end; end; procedure Tform1.draw;var x,y : integer;begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      if cel[x,y]=1 then begin        paintbox1.Canvas.Brush.color:=colorbutton1.buttoncolor;        end    else begin        paintbox1.Canvas.brush.color:=clWhite;        end;      paintbox1.canvas.FillRect(20+x*5,20+y*5,25+x*5,25+y*5);      end;    end; end; procedure Tform1.drawempty;var x,y : integer;begin   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      if cel[x,y]=1 then begin        paintbox1.Canvas.Brush.color:=clWhite;      end      else begin        paintbox1.Canvas.brush.color:=clWhite;        end;      paintbox1.canvas.FillRect(20+x*5,20+y*5,25+x*5,25+y*5);      end;    end; end; procedure Tform1.initiate;var x,y,number : integer;begin  sizeX:=75;  sizeY:=75;  startingchance := SpinEdit1.value;   Paintbox1.Width := SpinEdit2.Value;  Paintbox1.Height := SpinEdit3.Value;   for x:=1 to sizeX do begin    for y:=1 to sizeY do begin      getal:=randomrange(0,100);      if number