Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Adding TToolButton in TToolbar


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Oct 28, 2017 7:39 PM Last Post By: Lex Dean
Lex Dean

Posts: 132
Registered: 3/26/07
Adding TToolButton in TToolbar  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2017 2:50 AM
TToolbar in file ComCtrls

has
procedure InsertButton(Control: TControl); // I think moves buttons into the Toolbar
procedure RemoveButton(Control: TControl); // I think moves buttons out of the Toolbar
procedure CreateButtons(NewWidth, NewHeight: Integer); // not sure how to use

following these methods I realise I have many levels to insert a button into the tool bar
a) The create and parent set to the toolbar as you do with all components
b) Button.Style := tbsButton;
c) TToolButton.FToolBar := the TToolBar;
d) add the object to TToolBar's FButtons: TList;
e) Perform or example Perform(TB_BUTTONSTRUCTSIZE, SizeOf(TTBButton), 0);

Is Perform allocating memory to a bitmap, pointer to the button, button controls, and many other uses..................

Can I get a list of the Perform messages that are available to me for TToolbar, and what messages are necessary to make a stable ToolButton please.
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Adding TToolButton in TToolbar  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2017 3:28 PM   in response to: Lex Dean in response to: Lex Dean
I found CommCtrl.pas file I'm away I think
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Adding TToolButton in TToolbar  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 28, 2017 7:37 PM   in response to: Lex Dean in response to: Lex Dean
I have recreated TToolBar and supporting objects and placed it in a separate file
I runs perfectly in Run time
I have made the method CreateNewButton that works perfectly in run time but Not design time
The 1st half is obvious code that is realised from the objects

TTBButton is found in Delphi CommCtrl.pas and I found SendMessage(Handle, TB_ADDBUTTONS, 1, lParam(@TBButton)); from off the internet

Can I call HandleNeeded; in design time
Can TB_ADDBUTTONS be sent with a - Perform(TB_ADDBUTTONS, But.Index, lParam(@TBButton)); is this a better option so i do not need a handle.

In design time I get error - access violation 40005989 in rtl70.bpl. read of address 8BFFF80B. When using the method below.
But.Index is not the issue.


function TTBar.CreateNewButton: TTBut;
Var
  TBButton: TTBButton;
  But: TTBut;
Begin
   But := TTBut.Create(Self);
   But.Parent := Self;
   FButtons.Add(But);  // TList
   But.Style := tbsButton;
   But.FTBar := Self;  // link for button to find ToolBar
 
   TBButton.iBitmap := 0;
   TBButton.idCommand := But.Index;
   TBButton.fsState := TBSTATE_ENABLED;
   TBButton.fsStyle := TBSTYLE_BUTTON;
   TBButton.dwData := 0;
   TBButton.iString := 0;
   HandleNeeded;
   SendMessage(Handle, TB_ADDBUTTONS, 1, lParam(@TBButton));
   Result := But;
end;
 
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02