[Lazarus] Event created by program logic rather than user action
Dr Engelbert Buxbaum
engelbert_buxbaum at web.de
Sun Nov 8 17:17:27 CET 2015
Hi,
I am writing a cellular automaton, that calculates a n by n array with
integer values, which represent colour values. The array is updated in
an infinite loop, that I want to also call the FormPaint method to
create a graphical representation of the automaton. Who is the sender
in this case? Or is there a better way to do this?
Thanks for any help
Engelbert
unit CellularAutomaton;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
crt, LResources, BGRABitmap, BGRABitmapTypes;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
var Image : TBGRABitmap;
// code of no relevance to the question goes here
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Image := TBGRABitmap.Create(ScreenSize,ScreenSize,BGRABlack);
end;
procedure TForm1.FormPaint(Sender: TObject);
var p: PBGRAPixel;
x,y: integer;
begin
for y := 0 to Image.Height-1 do
begin
p := Image.Scanline[y];
for x := 0 to Image.Width-1 do
begin
IntToRGB(NewScreen[succ(y),succ(x)],p^.red, p^.green, p^.blue);
inc(p);
end;
end;
Image.InvalidateBitmap; // direkt Pixels access
Image.Draw(Canvas,0,0,True);
Image.Free;
end;
begin
Initialize(OldScreen);
Initialize(NewScreen);
repeat
Calculate(OldScreen, NewScreen);
CopyScreen(NewScreen, OldScreen);
TForm1.FormPaint(????????);
until keypressed;
end.
More information about the Lazarus
mailing list