{"id":91,"date":"2007-05-12T13:52:27","date_gmt":"2007-05-12T11:52:27","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/putting-controls-on-a-page-at-runtime\/"},"modified":"2007-05-12T13:52:28","modified_gmt":"2007-05-12T11:52:28","slug":"putting-controls-on-a-page-at-runtime","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/putting-controls-on-a-page-at-runtime\/","title":{"rendered":"Putting controls on a page at runtime"},"content":{"rendered":"<p><em>Q:<br \/>\nHi,<br \/>\nI need to create a component at runtime and &#8216;drop&#8217; it<br \/>\non a certain page of a multipage TNotebook &#8211; how<br \/>\ncan this be done since the Tnotebook doesn&#8217;t expose<br \/>\nthe pages &#8211; just their &#8216;names&#8217;.<br \/>\nFor various reasons I do not want to a TPageControl.<br \/>\n<\/em><br \/>\nA:<br \/>\nWell, i havn&#8217;t found an &#8216;easy&#8217; way but this:<\/p>\n<p>Use this function to get the TPage by it&#8217;s Caption:<\/p>\n<p>[code lang=&#8221;delphi&#8221;]function GetPageByCaption(NoteBook:TNoteBook; Cap:string):TPage;<br \/>\nvar<br \/>\n  i : integer;<br \/>\nbegin<br \/>\n  result := nil;<\/p>\n<p>  for i := 0 to NoteBook.ControlCount-1 do<br \/>\n  begin<br \/>\n    if NoteBook.Controls[i] is TPage then<br \/>\n      begin<br \/>\n        if UpperCase(TPage(NoteBook.Controls[i]).Caption) = UpperCase(Cap)<br \/>\nthen<br \/>\n          begin<br \/>\n            result := TPage(NoteBook.Controls[i]);<br \/>\n            break;<br \/>\n          end;<br \/>\n      end;<br \/>\n  end;<br \/>\nend;<br \/>\n[\/code]<br \/>\nThen you could do something like this:<\/p>\n<p>[code lang=&#8221;delphi&#8221;]var<br \/>\n  ThePage : TPage;<br \/>\nbegin<br \/>\n  ThePage := GetPageByCaption(NoteBook1, &#8216;Page1&#8217;);<br \/>\n  if ThePage <> nil then<br \/>\n    begin<br \/>\n      MyButton := TButton.Create(self);<br \/>\n      MyButton.Parent := ThePage;<br \/>\n      MyButton.Top := 10;<br \/>\n      MyButton.Left := 20;<br \/>\n    end;<br \/>\nend;<br \/>\n[\/code]<br \/>\nhave fun!<br \/>\nBoris Nienke<\/p>\n<p>Edit: &#8230;Much easier way is this:<br \/>\n[code lang=&#8221;delphi&#8221;]begin<br \/>\n  MyButton := TButton.Create(self);<br \/>\n  with MyButton do<br \/>\n  begin<br \/>\n    Parent := Notebook1.Pages.Objects[0] As TWinControl;<br \/>\n    Top := 10;<br \/>\n    Left := 20;<br \/>\n  end;<br \/>\nend;[\/code]<\/p>\n<p>[tags]Delphi, Components, Notebook[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Q: Hi, I need to create a component at runtime and &#8216;drop&#8217; it on a certain page of a multipage TNotebook &#8211; how&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[90,75,92],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1t","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/91"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}