Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Movable buttons

6 views
Skip to first unread message

Andrea Raimondi

unread,
Jul 1, 2008, 5:24:15 AM7/1/08
to
Hello.

I'm writing this application that needs to have several buttons: some will
show child buttons when pressed(categories) and others will show final
items(pdf files).

What hierarchy do you suggest to streamline my code?

TIA,

Andrew


Andrea Raimondi

unread,
Jul 1, 2008, 5:33:18 AM7/1/08
to
Forgot to add: they're going to be persisted in a db. My draft solution at
this point is:

unit ButtonHelpers;

interface

uses Classes;

Type

TButtonProperties = class( TPersistent )
private
FCaption: Integer;
FTop: Integer;
FLeft: Integer;
procedure SetCaption(const Value: Integer);
procedure SetLeft(const Value: Integer);
procedure SetTop(const Value: Integer);
protected
procedure InternalSave;virtual;abstract;
published
procedure Save;
property Left : Integer read FLeft write SetLeft;
property Top : Integer read FTop write SetTop;
property Caption : Integer read FCaption write SetCaption;
end;

THierarchyButtonProperties = class( TButtonProperties )
private
FDBId : String;
FIsNewID: Boolean;
function GetIsSubMenu: Boolean;
protected
procedure InternalSave;override;
public
constructor Create( ADBId : String;CreateNew : Boolean );
property DBId : String read FDBId;
property IsSubMenu : Boolean read GetIsSubMenu;
property IsNewId : Boolean read FIsNewID;
end;

function CreateNewID : String;

implementation

uses SysUtils, ActiveX, MenuConfDataModCode;

function NewGUID : TGUID;
begin
CoCreateGuid( Result );
end;

function CreateNewID : String;
begin
Result := GUIDToString( NewGUID );
end;

{ TButtonProperties }

procedure TButtonProperties.Save;
begin
InternalSave;
end;

procedure TButtonProperties.SetCaption(const Value: Integer);
begin
FCaption := Value;
end;

procedure TButtonProperties.SetLeft(const Value: Integer);
begin
FLeft := Value;
end;

procedure TButtonProperties.SetTop(const Value: Integer);
begin
FTop := Value;
end;

{ THierarchyButtonProperties }

constructor THierarchyButtonProperties.Create(ADBId: String;
CreateNew: Boolean);
begin
inherited Create;
if Not CreateNew then
begin
FDBId := ADBId;
end
else begin
FDBId := CreateNewID;
end;
FIsNewID := CreateNew;
end;

function THierarchyButtonProperties.GetIsSubMenu: Boolean;
var RecsAffected : Integer;
SelQuery : String;
begin
SelQuery := 'Select distinct GUIDSTRING from MenuConf';
MenuConfDataModule.ADOConn.Execute( SelQuery,RecsAffected,[ ] );
end;

procedure THierarchyButtonProperties.InternalSave;
begin

end;

end.

I will have then to link these classes to buttons(hints?) that, when
pressed, will behave accordingly.
I'm inheriting from TPersistent cause I want to use a TJvInspector to set
properties.

Andrew


Peter Below (TeamB)

unread,
Jul 1, 2008, 1:21:48 PM7/1/08
to
Andrea Raimondi wrote:

Looks like a task for a TTreeview, not for buttons.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Lee Jenkins

unread,
Jul 2, 2008, 12:22:55 AM7/2/08
to

Andrew,

I had a need to do this a while back for our company's touch screen pos
application. Basically, you'd have Categories of products that when touched,
would either drill down into sub categories (if sub categories were present) or
display products for that particular category on another part of the screen. It
works in its current form very well, but I'm thankful that I have not had to
change any part of that functionality ;)

I'm in the process of re-writing the application from a more procedural coding
standpoint to an OO, design pattern driven development now. To get this same
functionality, I've opted to use the Composite Pattern which has worked very
nicely.

http://en.wikipedia.org/wiki/Composite_pattern

Following this pattern, I have designed the application so that Categories
represent Composites and products represents leafs. What is so nice about this
pattern that I've found so far is that you get to treat both of them uniformly
in terms of displaying them and working with them in the GUI. A button doesn't
care if its right now representing a Category (composite) or a Leaf (product).
I've thrown in the observer and mediator patterns to handle the click logic for
the buttons and its working very nicely.

If you want to represent a hierarchy like that with buttons, I heartily
recommend taking a look at the composite pattern.

--
Warm Regards,

Lee

Andrea Raimondi

unread,
Jul 2, 2008, 10:49:03 AM7/2/08
to
> Looks like a task for a TTreeview, not for buttons.

Lee Jenkins got it almost correct ;-) mine's not a POS application but a
kiosk one :-)
Have got to use buttons(although I'd agree, using a treeview would be ages
easier :-P).

> Peter Below (TeamB)

Andrew


0 new messages