Jud 1 Posted January 11 I have 20 TMemos, named memo1 ... memo20. I have an integer which indicates which memo is to be written to. Is there a direct way to write to the desired memo, as opposed to a large, ugly case statement? Share this post Link to post
Remy Lebeau 1458 Posted January 11 (edited) The most direct/efficient way is to put the Memo object pointers into an array or list, and then use the integer as an index into that container. Edited January 11 by Remy Lebeau Share this post Link to post
Brian Evans 111 Posted January 11 (edited) As Remy already mentioned an array or list works. I tend to put such things in a dynamic array. Can move the array to someplace higher in scope if desired but for code that doesn't run that often I usually create it as needed and let it fall out of scope and be destroyed. procedure TForm1.Button1Click(Sender: TObject); Var SomeMemos : array of TMemo; begin SomeMemos := [Form1.Memo1,Form1.Memo2,Form1.Memo3,Form1.Memo4,Form1.Memo5]; // Dynamic Arrays are zero based so need to subtract one compared to 1 based SomeMemos[5 -1].Lines.Add('test!'); end; Edited January 11 by Brian Evans Share this post Link to post
Jud 1 Posted January 12 Thanks, it works well. You guys are the greatest! Share this post Link to post