Hello all!
I have written a simple Carbon program just to test Lazarus, and here are two problems that I have met:
1. Although the KeyPress event handler works, nothing is drawn on the Cavas.
2. As seen from the code, the FormKeyPress method should only move the form to a position 4 pixels to the right of the left side of the screen, but in fact only the first key press does it. All subsequent presses move the form 6 pixels to the right, as if the third line of the method was not executed.
I'll appreciate your help,
Anton
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
private
{ private declarations }
public
procedure PutCell(x,y:integer);
{ public declarations }
end;
var
Form1: TForm1;
implementation
const cellSize = 12;
const fieldWidth = 20;
const fieldHeight = 20;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
self.ClientHeight := fieldHeight*cellSize;
self.ClientWidth := fieldWidth*cellSize;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
PutCell(5,10);
inc(Self.Left,6);
self.Left:=4; //This line is executed only on the first invocation of the event
end;
procedure TForm1.PutCell(x,y:integer);
begin
self.Canvas.Brush.Color := clBlack;
self.Canvas.TextOut(30,60,'Hello!');
self.Canvas.FillRect(x*cellSize, y*cellSize, (x+1)*cellSize, (y+1)*cellSize); //Not working
end;
initialization
{$I unit1.lrs}
end.