Forum > Beginners
[SOLVED] Get All Objects in a ToolBar
tudi_x:
Hi!
I am creating several ToolBars in Form1.
For a ToolBar with specific Tag I need to enable a button with specific name that has parent this ToolBar.
I can find the ToolBar by parsing the Form1 elements as below.
--- 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";}};} ---PROCEDURE TForm1.OnChange_EditVal(Sender : TObject);VAR theTag : INTEGER; i, j : INTEGER; theparent : TWinControl; element_name : STRING; BEGIN WITH (Sender as TCDEdit) DO theTag := (Sender as TCDEdit).Tag; //Get the Tag aka Row FOR i := 0 TO TWinControl(Form1).ControlCount - 1 DO IF TWinControl(Form1).Controls[i] is TBCToolBar THEN BEGIN theparent := TWinControl(Form1).Controls[i]; if theparent.Name := inttostr(theTag) then begin FOR j := 0 TO TWinControl(theparent).Components[j] DO //does not work: main.pas(282,43) Error: Incompatible types: got "TComponent" expected "LongInt" BEGIN element_name := TWinControl(theparent).Controls[j].Name; IF element_name = btnPostUpdateName + IntToStr(theTag) THEN BEGIN TWinControl(Form1).Controls[i].Enabled := True; //Enable the button break; END; END; end; END;END;
How would I find the button once I have the ToolBar?
Thank you.
balazsszekely:
--- 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";}};} ---var I: Integer;begin for I := 0 to ToolBar1.ButtonCount - 1 do if ToolBar1.Buttons[I].Name = 'Test' then ShowMessage('ok');end;
PS: This is for TToolBar, what is TBCToolbar?
tudi_x:
TBCToolBar is tool bar from BGRA Controls.
Please note that I do not know how to get a handler of a TBCToolBar type.
I just know the name of the TBCToolBar but I think to your code I would need to send as parameter a TBCToolBar reference which I do not know how to obtain.
From parsing Form1 I get a TComponent in TWinControl(Form1).Controls.
Please advise.
tudi_x:
Thank you.
The reference send works with something like the below.
--- 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";}};} ---PROCEDURE TForm1.OnChange_EditVal(Sender : TObject);VAR theTag : INTEGER; i, j : INTEGER; BEGIN FOR i := 0 TO TWinControl(Form1).ControlCount - 1 DO IF TWinControl(Form1).Controls[i] is TBCToolBar THEN BEGIN with (TWinControl(Form1).Controls[i] as TBCToolBar ) do begin for j:= 0 to (TWinControl(Form1).Controls[i] as TBCToolBar ).ButtonCount - 1 do begin memo1.Append((TWinControl(Form1).Controls[i] as TBCToolBar ).Buttons[j].Name); if (TWinControl(Form1).Controls[i] as TBCToolBar ).Buttons[j].Name = btnPostUpdateName + IntToStr(theTag) then begin (TWinControl(Form1).Controls[i] as TBCToolBar ).Buttons[j].Enabled:= true; end; end; end; END;END;
balazsszekely:
You're welcome, I'm glad it's working! By the way, you figured out this one by yourself. ;)
Navigation
[0] Message Index
[#] Next page