Create StringGrid control using code. lazarus / 31-LCL ---------------------------------------------------------------------- allanregistos · 2016-07-04 02:41 Having created a PageControl using code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Var  TabSheet: TTabSheet;   Begin   NumberOfSheet := PageControl1.PageCount;  TabSheet := TTabSheet.Create(PageControl1);  TabSheet.Caption:='Tab ' + IntToStr(NumberOfSheet + 1);  TabSheet.PageControl:= PageControl1;  End;  How can I create a StringGrid inside the created TabSheet of PageControl using code? Thank you, -Allan ---------------------------------------------------------------------- molly · 2016-07-04 03:07 if not mistaken (cannot check currently as no lazarus in the neighbourhood): Code: [Select]Var   TabSheet   : TTabSheet;    StringGrid : TStringGrid; Begin   NumberOfSheet := PageControl1.PageCount;   TabSheet := TTabSheet.Create(PageControl1);   TabSheet.Caption:='Tab ' + IntToStr(NumberOfSheet + 1);   TabSheet.PageControl:= PageControl1;    StringGrid := TStringGrid.Create(Form1); // owner is usually a form and not another component (although not invalid)   StringGrid.Parent := TabSheet; // parent _must_ be the control on which you want to place the dynamic control.   StringGrid.Left := 10;   StringGrid.Top  := 100;   etc.  End; You probably have to add unit Grids to your uses clause as well. ---------------------------------------------------------------------- allanregistos · 2016-07-04 03:21 Quote from: molly on July 04, 2016, 05:07:04 amif not mistaken (cannot check currently as no lazarus in the neighbourhood): Code: [Select]Var   TabSheet   : TTabSheet;    StringGrid : TStringGrid; Begin   NumberOfSheet := PageControl1.PageCount;   TabSheet := TTabSheet.Create(PageControl1);   TabSheet.Caption:='Tab ' + IntToStr(NumberOfSheet + 1);   TabSheet.PageControl:= PageControl1;    StringGrid := TStringGrid.Create(Form1); // owner is usually a form and not another component (although not invalid)   StringGrid.Parent := TabSheet; // parent _must_ be the control on which you want to place the dynamic control.   StringGrid.Left := 10;   StringGrid.Top  := 100;   etc.  End; You probably have to add unit Grids to your uses clause as well. Perfect! Thank you molly, -Allan ---------------------------------------------------------------------- allanregistos · 2016-07-04 05:35 Quote from: molly on July 04, 2016, 05:07:04 amif not mistaken (cannot check currently as no lazarus in the neighbourhood): Code: [Select]Var   TabSheet   : TTabSheet;    StringGrid : TStringGrid; Begin   NumberOfSheet := PageControl1.PageCount;   TabSheet := TTabSheet.Create(PageControl1);   TabSheet.Caption:='Tab ' + IntToStr(NumberOfSheet + 1);   TabSheet.PageControl:= PageControl1;    StringGrid := TStringGrid.Create(Form1); // owner is usually a form and not another component (although not invalid)   StringGrid.Parent := TabSheet; // parent _must_ be the control on which you want to place the dynamic control.   StringGrid.Left := 10;   StringGrid.Top  := 100;   etc.  End; You probably have to add unit Grids to your uses clause as well. Thank you, if its okay to ask a related question, how can I access or create events for the newly created Stringgrid such as OnSelectCell? I tried using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i WorkSheet.OnClick:= @StringGrid1SelectCell; but does not work, the error is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mainui.pas(181,23) Error: Incompatible types: got "" expected "" ---------------------------------------------------------------------- allanregistos · 2016-07-04 05:49 Ok got it, I just copied the SelectCellEvent to create the event procedure  then call: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i WorkSheet.OnSelectCell:= @AnotherStringGridSelecCellEvent; ---------------------------------------------------------------------- molly · 2016-07-04 06:34 @allanregistos: Creating controls dynamically is an art of its own Often i find myself puzzled as well. In order to investigate "what should have been", simply create what you had in mind by using the visual builder inside lazarus IDE. Just drop the components on a form and design as you would have done by code. You can then use the object inspector to investigate what values certain properties can have (and what their default values are), and in the events tab of the inspector you can double-click on an event to let the code-editor show you the declaration of the event procedure. e.g. what kind of and how many parameters (and their types) the event require. In case you need some information on the creation order of things (e.g. which component belongs to what etc.) you can take a peek at the .lfm file. Even stronger: in case creating components dynamically and there are a lot of settings that needs to be changed then i do it inside lazarus IDE visually, then copy paste from the .lfm file. In my code i use a simple "with name_of_dynamically_create_component do begin ... end". The dots represents the relevant part from the .lfm file, which after a copy needs the "=" replaced with ":=" and each line needs to be terminated with a ";" character. Easy as pi :-) hmz, isn't there a tool that already does that automatically for us ? There are simply too many components out there to remember all their specifics. That's one of the reasons i like these RAD tools, with their object inspectors and automatic code-insertions and all.