Dear All,

Could you tell me what is / are wrong of the coding?

Cheers,

Dear turbomen,

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
//  Application.MainFormOnTaskbar := True; { under Delphi 7 this is a wrong code line }
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    DrawGrid1: TDrawGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Image1: TImage;
    Image2: TImage;
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
  Temp: TRect;
begin
  // to colour a cell in the grid:
  Temp:= DrawGrid1.CellRect(0,4);   //identify the cell
  DrawGrid1.Canvas.Brush.Color:= clRed; //set colour
  DrawGrid1.Canvas.FillRect(Temp);  //colour cell
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Temp: TRect;
begin
   // to put bitmap into a cell on the grid:
  // the bitmap is loaded into an image on the form. visible property is set to invisible, then
  Temp:= DrawGrid1.CellRect(5,1);    //identify cell
  DrawGrid1.Canvas.Draw(Temp.Left, Temp.Top, Image1.Picture.Graphic);  //load image
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  GridString: string;
  Position: integer;
  ColCount, RowCount: Integer;
  Temp: TRect;
begin
  GridString:= 'rbb'+ 'rwb' + 'rsr';

  for ColCount:=0 to 2 do
    begin
      for RowCount:=0 to 2 do
        begin
          Position:=(RowCount*3)+ColCount+1;
          Temp:=DrawGrid1.CellRect(ColCount,RowCount);   //identify the cell

          case GridString[Position] of
          'r': begin
                 DrawGrid1.Canvas.Brush.Color:=clRed;     //set colour
                 DrawGrid1.Canvas.FillRect(Temp);         //colour cell
               end;

          'b': begin
                 DrawGrid1.Canvas.Brush.Color:=clBlack;    //set colour
                 DrawGrid1.Canvas.FillRect(Temp);          //colour cell
               end;

          'w': begin
                 DrawGrid1.Canvas.Brush.Color:=clWhite;    //set colour
                 DrawGrid1.Canvas.FillRect(Temp);          //colour cell
               end;

          's': begin
                 DrawGrid1.Canvas.Draw(Temp.Left, Temp.Top, Image2.Picture.Graphic);     //load image
               end;

        end;
    end;

  end;
  ActiveControl:=DrawGrid1;
end;

(*
{ The next method is not declared in the TForm1, and not assigned with Event OnClick, so it is wrong }
procedure TForm1.Image2Click(Sender: TObject);
begin

end;
*)

end.

In addition it can be mentioned, that some properties are different for DrawGrid1 on Form1 in Project1 and prjDemo ....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.