Hi All,
I have a new component called Tarraybutton which is meant to display a
grid-like array of tbuttons (actually TGridButtons -- but you could
change it to tbutton for debugging). It compiles fine but when I use it
at design time and change the number of RowCount and ColCount these do
NOT affect the displayed number of rows and columns. This is supposed to
work like a TStringGrid, except with Buttons.
I think that I have forgotten to include the code which tells it how to
display the component. Can someone please help me to debug this
component???
Best Regards,
PEW
Hobart, Tasmania, Australia
unit arraybutton;
//{$MODE Delphi}
{$mode objfpc}{$H+}
{ ------------------------------------------------------------
Author: Unknown +
------ modifications by Peter E. Williams +
suggestions from alt.comp.lang.borland-delphi newsgroup +
suggestions from Mark Meyer in
[email protected].
This code is freeware and is placed into the Public Domain by Peter E.
Williams
( [email protected] ).
Version 0.1a - for Lazarus by PEW
Date: 17 June 2010
Added :--------
FRowCount, FColCount: integer;
procedure SetRowCount(r: integer);
procedure SetColCount(c: integer);
Version: 0.04a - by PEW. 'col' changed to 'column'. Setcol changed to
setcolumn.
interface
uses
{Windows,}{ Messages,} SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
{StdCtrls,}
LcLType, lresources,
ugradbtn;
type
TOnArrowKeyEvent = procedure( Sender: TObject;
Key: Word;
Row: integer;
Column: integer;
RowCount : integer; // new
ColCount : integer; // new
var handled: boolean) of object;
TArrayButton = class(TGradButton) { class(TButton) }
private
IsFocused: Boolean;
FCanvas: TCanvas;
FRow,FColumn, FRowCount, FColCount: integer;
FUseDefaultKeyHandler : boolean;
FOnArrowKey : TOnArrowKeyEvent;
procedure SetRow(r: integer);
procedure SetColumn(c: integer);
procedure SetRowCount(r: integer);
procedure SetColCount(c: integer);
procedure TArrayButton.SetRowCount(r: integer);
begin
if r>-1 then
FRowCount:= r;
end;
{------------------------------------------------------------}
procedure TArrayButton.SetColCount(c: integer);
begin
if c>-1 then
FColCount:= c;
end;
{------------------------------------------------------------}
--
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)
unit arraybutton;
//{$MODE Delphi}
{$mode objfpc}{$H+}
{ ------------------------------------------------------------
Author: Unknown +
------ modifications by Peter E. Williams +
suggestions from alt.comp.lang.borland-delphi newsgroup +
suggestions from Mark Meyer in [email protected].
This code is freeware and is placed into the Public Domain by Peter E. Williams
( [email protected] ).
Version 0.1a - for Lazarus by PEW
Date: 17 June 2010
Added :--------
FRowCount, FColCount: integer;
procedure SetRowCount(r: integer);
procedure SetColCount(c: integer);
Version: 0.04a - by PEW. 'col' changed to 'column'. Setcol changed to
setcolumn.
Previous versions:
-----------------
Versions: 0.03a to 0.03f - trial versions to declare component based
on tcustomcontrol instead of on tbutton. Unsuccessful.
Version: 0.02b - mods by Mark Meyer + PEW.
Version: 0.02 - Dated: 15 February 2001
Version: 0.01 - Dated: 14 April 2000
Modified to form new unit based on AColorBtn & arraybtn,
based entirely on Acolorbtn with Row & Column properties of arraybtn added.
Note: The only difference between this component and AColorBtn is
* essentially that this component has additional 'row' & 'Column' published
properties.
Thanks and Acknowledgements:
---------------------------
Thanks to the unknown person who originally sent me version 0.01 of this code,
and to Bruce Roberts ([email protected]) who posted up v0.02 modifications
to the ng. Thanks also to all those in the alt.comp.lang.borland-delphi newsgroup
for their discussion of it and support.
Last modified by: Peter E. Williams
Known bugs:
----------
(#1 is now fixed!!!)
#1 - Captions containing #13 characters are displayed as
as single line of text.
#2 - There is no visual difference between Enabled true or false. The
Enabled property works otherwise as normal. Workaround is to use
the Font.Style settings to show when a button is Enabled, e.g.
for Enabled = true set to [fsbold], false set to [fsitalic] (this
is NOT done automatically).
#3 - Color property is assigned an invalid value of clCream.
Reported by "Mark Meyer" <gee...@g...>
(via [email protected])
Available from:
?????????????? http://www.angelfire.com/biz6/pwillcomputing/peter_delphi_page.html
as filename:
arraycolorbtn_src.zip
------------------------------------------------------------
}
interface
uses
{Windows,}{ Messages,} SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
{StdCtrls,}
LcLType, lresources,
ugradbtn;
type
TOnArrowKeyEvent = procedure( Sender: TObject;
Key: Word;
Row: integer;
Column: integer;
RowCount : integer; // new
ColCount : integer; // new
var handled: boolean) of object;
TArrayButton = class(TGradButton) { class(TButton) }
private
IsFocused: Boolean;
FCanvas: TCanvas;
FRow,FColumn, FRowCount, FColCount: integer;
FUseDefaultKeyHandler : boolean;
FOnArrowKey : TOnArrowKeyEvent;
procedure SetRow(r: integer);
procedure SetColumn(c: integer);
procedure SetRowCount(r: integer);
procedure SetColCount(c: integer);
{
procedure CNDrawItem(var Msg: MDrawItemStruct); message CN_DRAWITEM;
//procedure CNDrawItem(var Msg: TWMDrawItem); message CN_DRAWITEM;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
message WM_LBUTTONDBLCLK;
}
protected
// procedure CreateParams(var Params: TCreateParams); override;
// procedure CreateWnd; override;
// procedure SetButtonStyle(ADefault: Boolean); override;
procedure DoArrowKey(key : word);
public
// procedure SetBounds (ALeft, ATop, AWidth, AHeight: Integer); override;
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure KeyPress(var Key: Char); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
published
property UseDefaultKeyHandler: boolean read FUseDefaultKeyHandler write FUseDefaultKeyHandler;
property OnArrowKey : TOnArrowKeyEvent read FOnArrowKey write FOnArrowKey;
property Row: integer read FRow write SetRow default 1;
property Column: integer read FColumn write SetColumn default 1;
property RowCount: integer read FRowCount write SetRowCount default 1;
property ColCount: integer read FColCount write SetColCount default 1;
property Color;
property Width default 75;
property Height default 25;
property ParentShowHint;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnEnter;
property OnExit;
end;
procedure Register;
implementation
{------------------------------------------------------------}
procedure TArrayButton.KeyPress(var Key: char);
begin
if (FUseDefaultKeyHandler) then
begin
inherited;
// messagedlg('using default',mtinformation,[mbok],0);
end{if}
else
begin
DoArrowKey(word(key));
end;
end;
{------------------------------------------------------------}
procedure TArrayButton.KeyUp(var Key: Word; Shift: TShiftState);
begin
if (FUseDefaultKeyHandler) then
begin
inherited;
// messagedlg('using default keyup',mtinformation,[mbok],0);
end{if}
else
begin
DoArrowKey(key);
end;
end;
{------------------------------------------------------------}
procedure TArrayButton.KeyDown(var Key: Word; Shift: TShiftState);
begin
if (FUseDefaultKeyHandler) then
begin
inherited;
// messagedlg('using default keydown',mtinformation,[mbok],0);
end{if}
else
begin
DoArrowKey(key);
end;
end;
{------------------------------------------------------------}
procedure TArrayButton.DoArrowKey(Key: Word);
var
handled : boolean;
begin
handled := false;
(*
i am unsure what is going to be best for you or what you have visualized here
to call an event here seems somewhat redundant - you could really do this
inside of the overriden events for keypress, keydown, and keyup - but you
know better what it is you want to do
if you do want to call your own event - say with some additional info - then use
the following code
[ comment by Mark Meyer ]
*)
case key of
VK_UP, VK_DOWN, VK_RIGHT, VK_LEFT :
if assigned(FOnArrowKey) then
FOnArrowKey(self, key, self.row, self.Column,
self.RowCount, self.ColCount, // new
handled);
end;{case}
end;
{------------------------------------------------------------}
constructor TArrayButton.Create(AOwner: TComponent);
begin
inherited Create (AOwner);
SetBounds (Left, Top, 75, 25);
FCanvas := TCanvas.Create;
FRow:=1;
FColumn:=1;
FRowCount:=1;
FColCount:=1;
//##########
end;
{------------------------------------------------------------}
destructor TArrayButton.Destroy;
begin
inherited Destroy;
FCanvas.Free;
end;
{------------------------------------------------------------}
{
procedure TArrayButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params
do Style := Style or bs_OwnerDraw;
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.CreateWnd;
begin
inherited CreateWnd;
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.SetBounds (ALeft, ATop,
AWidth, AHeight: Integer);
begin
inherited SetBounds (ALeft, ATop, AWidth, AHeight);
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.CMFontChanged(var Msg: TMessage);
begin
inherited;
Invalidate;
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.CMEnabledChanged(var Msg: TMessage);
begin
inherited;
Invalidate;
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
Perform(WM_LBUTTONDOWN, Message.Keys, Longint(Message.Pos));
end;
}
{------------------------------------------------------------}
{
procedure TArrayButton.SetButtonStyle(ADefault: Boolean);
begin
if ADefault <> IsFocused then
begin
IsFocused := ADefault;
Invalidate;
end;
end;
}
{------------------------------------------------------------}
procedure TArrayButton.SetRow(r: integer);
begin
if r>-1 then
FRow:= r;
end;
{------------------------------------------------------------}
procedure TArrayButton.SetColumn(c: integer);
begin
if c>-1 then
FColumn:= c;
end;
{------------------------------------------------------------}
procedure TArrayButton.SetRowCount(r: integer);
begin
if r>-1 then
FRowCount:= r;
end;
{------------------------------------------------------------}
procedure TArrayButton.SetColCount(c: integer);
begin
if c>-1 then
FColCount:= c;
end;
{------------------------------------------------------------}
procedure Register;
begin
RegisterComponents('Misc',[TArrayButton]);
end;
initialization
{$I tarraybutton.lrs}
end.
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus