Witam. Mam problem:
Próbuję napisać aplikację, która wyświetla współrzędne pikseli PaintBox'a, na których kliknęliśmy myszą.
Proszę o pomoc w znalezieniu błędu.
Mój program (bez względu na to ile punktów wybierzemy w ComboBox) wyświetla tylko współrzędne pierwszego i ostatniego piksela. Pełnie popełniłem jakiś błąd w pętli, ale nie widzę go.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ComboBox1: TComboBox;
PaintBox1: TPaintBox;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;
type
TPoint = record
A: longint;
B: longint;
end;
var
Form1: TForm1;
POINTS_ARR: array of TPoint;
i:integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SetLength(POINTS_ARR,ComboBox1.ItemIndex+3);
PaintBox1.Canvas.Pixels[X,Y]:=clRed;
POINTS_ARR[i].A:=X;
POINTS_ARR[i].B:=Y;
for i:=0 to ComboBox1.ItemIndex+2 do
begin
StringGrid1.Cells[1,i]:=IntToStr(POINTS_ARR[i].A);
StringGrid1.Cells[2,i]:=IntToStr(POINTS_ARR[i].B);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
liczbawierszy:integer;
begin
liczbawierszy:=ComboBox1.ItemIndex+3;
StringGrid1.RowCount:=liczbawierszy;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
end;
end.