Sudoku: rename variables, make form a dialog (not resizable), set form caption.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7227 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
lazarus-bart
2020-01-04 16:41:52 +00:00
parent a95b456fb5
commit 20e629be7a
2 changed files with 22 additions and 21 deletions

View File

@ -6,12 +6,13 @@ object Form1: TForm1
HorzScrollBar.Page = 271
VertScrollBar.Page = 280
ActiveControl = ButtonFill
Caption = 'Form1'
BorderStyle = bsDialog
Caption = 'Sudoku Solver'
ClientHeight = 359
ClientWidth = 333
OnActivate = FormActivate
LCLVersion = '2.1.0.0'
object StringGrid1: TStringGrid
object SGrid: TStringGrid
Left = 16
Height = 280
Top = 16
@ -25,8 +26,8 @@ object Form1: TForm1
RowCount = 9
ScrollBars = ssNone
TabOrder = 2
OnPrepareCanvas = StringGrid1PrepareCanvas
OnSetEditText = StringGrid1SetEditText
OnPrepareCanvas = SGridPrepareCanvas
OnSetEditText = SGridSetEditText
end
object ButtonFill: TButton
Left = 16

View File

@ -40,13 +40,13 @@ type
TForm1 = class(TForm)
ButtonSolve: TButton;
ButtonFill: TButton;
StringGrid1: TStringGrid;
SGrid: TStringGrid;
procedure ButtonFillClick(Sender: TObject);
procedure ButtonSolveClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
procedure SGridPrepareCanvas(sender: TObject; aCol, aRow: Integer;
{%H-}aState: TGridDrawState);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
procedure SGridSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
private
{ private declarations }
@ -70,16 +70,16 @@ procedure TForm1.ButtonFillClick(Sender: TObject);
var
c, r: Integer;
begin
for c := 0 to pred(StringGrid1.ColCount) do
for r := 0 to pred(StringGrid1.RowCount) do
StringGrid1.Cells[c, r] := '';
StringGrid1.Options := StringGrid1.Options + [goEditing];
StringGrid1.SetFocus;
for c := 0 to pred(SGrid.ColCount) do
for r := 0 to pred(SGrid.RowCount) do
SGrid.Cells[c, r] := '';
SGrid.Options := SGrid.Options + [goEditing];
SGrid.SetFocus;
end;
procedure TForm1.ButtonSolveClick(Sender: TObject);
begin
StringGrid1.Options := StringGrid1.Options - [goEditing];
SGrid.Options := SGrid.Options - [goEditing];
SolveSudoku;
ShowSolution;
end;
@ -87,12 +87,12 @@ end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Self.OnActivate := nil;
StringGrid1.ClientWidth := 9 * StringGrid1.DefaultColWidth;
StringGrid1.ClientHeight := 9 * StringGrid1.DefaultRowHeight;
ClientWidth := 2 * StringGrid1.Left + StringGrid1.Width;
SGrid.ClientWidth := 9 * SGrid.DefaultColWidth;
SGrid.ClientHeight := 9 * SGrid.DefaultRowHeight;
ClientWidth := 2 * SGrid.Left + SGrid.Width;
end;
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
procedure TForm1.SGridPrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
var
NeedsColor: Boolean;
@ -116,7 +116,7 @@ begin
(Sender as TStringGrid).Canvas.Brush.Color := $00EEEEEE;
end;
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
procedure TForm1.SGridSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
begin
if (Length(Value) >= 1) and (Value[1] in ['1'..'9']) then begin
@ -134,9 +134,9 @@ var
begin
for Col := 0 to 8 do begin
for Row := 0 to 8 do begin
if Length(StringGrid1.Cells[Col, Row]) >= 1 then
if Length(SGrid.Cells[Col, Row]) >= 1 then
begin
theValues[Col + 1, Row + 1] := StringGrid1.Cells[Col, Row][1];
theValues[Col + 1, Row + 1] := SGrid.Cells[Col, Row][1];
end
else
begin
@ -165,7 +165,7 @@ begin
Ch := theValues[Col + 1, Row + 1];
if Ch = '0' then
Ch := #32;
StringGrid1.Cells[Col, Row] := Ch;
SGrid.Cells[Col, Row] := Ch;
end;
end;
end;