Forum > Beginners
[SOLVED] Get All Objects in a ToolBar
tudi_x:
In the code below and attached the number of buttons in the toolbar is shown as zero although toolbar is parent to 4 buttons.
Please advise what I am missing as with other type of buttons I have different than zero values.
Thank you.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit main; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, CustomDrawnControls, StdCtrls, customdrawndrawers; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; CDButton1: TCDButton; CDButton2: TCDButton; CDButton3: TCDButton; Memo1: TMemo; ToolBar1: TToolBar; procedure Button1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var i, j:integer; begin memo1.Clear; memo1.Append(CDButton1.Parent.Name); memo1.Append(CDButton2.Parent.Name); memo1.Append(CDButton3.Parent.Name); memo1.Append(Button2.Parent.Name); j:=ToolBar1.ButtonCount; //shows 0 memo1.Append(inttostr(j)); for i:= 0 to ToolBar1.ButtonCount - 1 do begin memo1.Append(ToolBar1.Buttons[i].Name); end;end; end.
balazsszekely:
ButtonCount is zero because you place a TCDButton to a TToolBar. Combine TToolBar with TToolButton or TBCToolBar with TCDButton and you should be fine.
tudi_x:
Now I see that ButtonCount and ComponentCount do not count but TToolButton.
ControlCount counts also other type of buttons.
Thank you!
Navigation
[0] Message Index
[*] Previous page