[Lazarus] How to create: TButtonGrid descendant of TCustomDrawGrid ?

Peter E Williams foss.game.pascal.developer at iinet.net.au
Sun Aug 29 01:54:23 CEST 2010


Hi Howard and All,

I copied your code (below) into a new application's unit1.pas but I
could not get it to compile.

unit1.pas(15,20) Warning: An inherited method is hidden by "constructor
TButtonGrid.Create(TComponent,LongWord,LongWord);"

// this would indicate to me that the parameters you have as cardinals
are supposed to be LongWords. Also, do we have to do something to tell
Lazarus that this is an inherited constructor???

unit1.pas(35,1) Error: Illegal expression
unit1.pas(35,13) Fatal: Syntax error, ";" expected but "identifier
TBUTTONGRID" found

type
   { TButtonGrid }

   TButtonGrid = class(TStringGrid)
     public
//line 15
       constructor Create(AOwner: TComponent; rowws, colls: cardinal);
   end;

{ TButtonGrid }

//line 35
constructor TButtonGrid.Create(AOwner: TComponent; rowws, colls:
cardinal);
var i, j, k: cardinal;
begin

Was I meant to save it as TButtonGrid.pas instead ???

> On 28/8/10 10:31, Peter E Williams wrote:
> > Hi,
> >
> > This email is related to my previous post.
> >
> > I want to create a new component called a TButtonGrid which would be
> a
> > descendant of TCustomDrawGrid. Problem is that I don't know how to
> do
> > that. Obviously, I would need to make the CustomDraw (???) draw a
> > TButton.
> >
> > Does anyone have some example(s) of how to do this, please???
> 
> Is this the sort of thing you want?
> 
> unit Unit1;
> 
> {$mode objfpc}{$H+}
> 
> interface
> 
> uses
>    Classes, Grids, SysUtils, FileUtil, Forms, Controls, Graphics,
> Dialogs;
> 
> type
>    { TButtonGrid }
> 
>    TButtonGrid = class(TStringGrid)
>      public
>        constructor Create(AOwner: TComponent; rowws, colls: cardinal);
>    end;
> 
>    { TForm1 }
> 
>    TForm1 = class(TForm)
>      procedure FormCreate(Sender: TObject);
>    private
>      btnGrid: TButtonGrid;
>    end;
> 
> var
>    Form1: TForm1;
> 
> implementation
> 
> {$R *.lfm}
> 
> { TButtonGrid }
> 
> constructor TButtonGrid.Create(AOwner: TComponent; rowws, colls:
> cardinal);
> var i, j, k: cardinal;
> begin
>   inherited Create(AOwner);
>   Parent := TWinControl(AOwner);
>   Left := 10;
>   Top := 10;
>   Width := colls*DefaultColWidth;
>   Height := rowws*DefaultRowHeight;
>   ExtendedSelect := False;
>   FixedCols := 0;
>   FixedRows := 0;
>   GridLineWidth := 0;
>   AutoEdit := False;
>   BorderStyle := bsNone;
>   RowCount := rowws;
>   ColCount := colls;
>   for j := 0 to colls - 1 do
>     with Columns.Add do
>       ButtonStyle := cbsButtonColumn;
>   k := 1;
>   for i := 0 to rowws-1 do
>     for j := 0 to colls-1 do
>       begin
>         Cells[j, i] := Format('Btn %d',[k]);
>         inc(k);
>       end;
> end;
> 
> { TForm1 }
> 
> procedure TForm1.FormCreate(Sender: TObject);
> begin
>    btnGrid := TButtonGrid.Create(self, 6, 4);
> end;
> 
> end.
> 
> Howard

-- 
Proudly developing Quality Cross Platform Open Source Games
Since 1970 with a Commodore PET 4016 with 16 KRAM
http://pews-freeware-games.org (<--- brand new)





More information about the Lazarus mailing list