Dynamic variables lazarus / 61-Beginners ---------------------------------------------------------------------- Trenatos · 2015-08-12 18:53 I've looked but not found. How do I reference a TSynEdit dynamically? I'm creating a bunch through an array, with names SynEdit[1..50], works fine, but I can't figure out how to reference it dynamically. I have a variable called currentServer, which holds an integer, which I'd like to use to reference the TSynEdit component. ---------------------------------------------------------------------- taazz · 2015-08-12 19:02 provide some code to get specific answers eg how is synedit[1..50] defined? How it gets its values? with out those two pieces of informaiton is impossible to answer. ---------------------------------------------------------------------- Trenatos · 2015-08-12 19:10 No problem, here's the code that generates the SynEdits Code: [Select]for i := 2 to 50 do   begin     SEdit := TSynEdit.Create(Self);     SEdit.Parent := Self;     SEdit.Name:= 'SynEdit'+ intToStr(i);     SEdit.AnchorToNeighbour(akLeft, 0, serverList);     SEdit.AnchorToNeighbour(akTop, 10, startServerButton);     SEdit.AnchorToNeighbour(akBottom, 0, Form1);     SEdit.AnchorToNeighbour(akRight, 0, Form1);     SEdit.AnchorSide[akBottom].Side:=asrBottom;     SEdit.AnchorSide[akBottom].Control:=Form1;     SEdit.AnchorSide[akRight].Side:=asrRight;     SEdit.AnchorSide[akRight].Control:=Form1;     SEdit.options := [eoGroupUndo,eoHideRightMargin,eoNoCaret,eoSmartT abs,eoTabsToSpaces,eoTrimTrailingSpaces];   end; I have an onClick for a TCheckListBox where I want to set the visibility based on what was clicked, I'm already grabbing the index and know what's clicked, but haven't figured out how to reference the SynEdits dynamically. ---------------------------------------------------------------------- derek.john.evans · 2015-08-12 19:15 FindComponent('SynEdit'+ intToStr(currentServer)) as TSynEdit ---------------------------------------------------------------------- Trenatos · 2015-08-12 19:19 derek my man, I owe you a case of beer by now. ---------------------------------------------------------------------- taazz · 2015-08-12 19:22 Quote from: Trenatos on August 12, 2015, 09:10:31 pmNo problem, here's the code that generates the SynEdits Code: [Select]for i := 2 to 50 do   begin     SEdit := TSynEdit.Create(Self);     SEdit.Parent := Self;     SEdit.Name:= 'SynEdit'+ intToStr(i);     SEdit.AnchorToNeighbour(akLeft, 0, serverList);     SEdit.AnchorToNeighbour(akTop, 10, startServerButton);     SEdit.AnchorToNeighbour(akBottom, 0, Form1);     SEdit.AnchorToNeighbour(akRight, 0, Form1);     SEdit.AnchorSide[akBottom].Side:=asrBottom;     SEdit.AnchorSide[akBottom].Control:=Form1;     SEdit.AnchorSide[akRight].Side:=asrRight;     SEdit.AnchorSide[akRight].Control:=Form1;     SEdit.options := [eoGroupUndo,eoHideRightMargin,eoNoCaret,eoSmartT abs,eoTabsToSpaces,eoTrimTrailingSpaces];   end; I have an onClick for a TCheckListBox where I want to set the visibility based on what was clicked, I'm already grabbing the index and know what's clicked, but haven't figured out how to reference the SynEdits dynamically. You do not keep the memory address where each synedit control is placed in memory any where that means that you don't have access to it any more. Lucky you, LCL is smart enough to keep a reference for you. So assuming that self in your code is a form then you can use the component[aIndex] and ComponentCount to search for the component you want eg. function GetSyneditControl(aIndex:integer):TSynedit;\ var   vCntr : integer; begin   Result := nil   for vCntr := 0 to ComponentCount -1 do begin     if Components[vCntr].name =  'SynEdit'+aIndex then begin       result := TSynedit(components[vCntr]);       break;       //those two lines I think can be written as Exit(TSynedit(components[vCntr])); too not sure though haven't used it enough to be sure.     end;   end; end; ---------------------------------------------------------------------- Trenatos · 2015-08-12 19:28 dereks code was the last bit needed to make the whole thing work, and yes derek I ended up with the individual SynEdits just as you suggested. I now have multi-threaded separate jetty instances running! ---------------------------------------------------------------------- derek.john.evans · 2015-08-12 19:38 Cool. Note, you could also add the TSynEdit to the TCheckListBox. Code: [Select]CheckListBox1.AddItem(SynEdit.Name, SynEdit); Which would of made it easy to get the TSynEdit pointer via: Code: [Select]CheckListBox1.Items.Objects[currentServer] as TSynEdit; Ie: Using the TCheckListBox as an array of objects.