[Lazarus] How to configure IDE for my own libraries?

Frank Church vfclists at gmail.com
Mon Aug 30 09:41:02 CEST 2010


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




More information about the Lazarus mailing list