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

View File

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