Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-08

How to create: TButtonGrid descendant of TCustomDrawGrid ?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter E Williams

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???

http://wiki.lazarus.freepascal.org/Grids_Reference_Page

Inheritence Tree
================

[TCustomControl]
|
|
TCustomGrid
|
+-------------+------------+
| |
TCustomDrawGrid TCustomDbGrid
| |
+--------+--------+ |
| | TDbGrid
TDrawGrid TCustomStringGrid
|
|
TStringGrid

Best Regards,
PEW
Hobart, Tasmania, Australia

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)

Reply by email

Howard Page-Clark
to Peter E Williams
Peter E Williams wrote 10 lines
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

Reply by email

Peter E Williams

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 ???

Show quoted text 91 lines
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)

Reply by email

Juha Manninen gmail
to Peter E Williams
Peter E Williams wrote 34 lines
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 ???

No, they are in one unit. It works well here.
You can get rid of the warning by adding "reintroduce;" at the end of contructor definition.

Juha

Reply by email

ik
to Peter E Williams: This email is related to my previous post. I want to create a new component called a…

Hi,

I've created this component. You can find it at:
http://github.com/ik5/linesip-components/blob/master/buttons/untbuttonlist.pas

Ido
http://ik.homelinux.org/

On Sun, Aug 29, 2010 at 00:31, Peter E Williams <

Show quoted text 50 lines
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??? http://wiki.lazarus.freepascal.org/Grids_Reference_Page Inheritence Tree ================ [TCustomControl] | | TCustomGrid | +-------------+------------+ | | TCustomDrawGrid TCustomDbGrid | | +--------+--------+ | | | TDbGrid TDrawGrid TCustomStringGrid | | TStringGrid Best Regards, PEW Hobart, Tasmania, Australia -- 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) -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100829/fffbca45/attachment-0001.html>

Reply by email