Also would be easier to set these properties on the object before you add it:
oComboBox.Top = nTop ComboBox.Left = nLeft oComboBox.Visible = .T. On Mon, Jun 17, 2024 at 3:19 PM Eric Selje <e...@saltydogllc.com> wrote: > The 'name' is read only after the object is created. You have to name it > when you create it, like you had in the commented out code: > > toForm.AddObject("oComboBox", (cname)) > > Except don't put cName in (), because that will try to interpolate cName > as a variable. And the parameters are reversed, it's name first and then > object name. > > So... > > toForm.AddObject(cName, "oComboBox") && This should work > > Eric > > > On Mon, Jun 17, 2024 at 3:02 PM Joe Yoder <j...@wheypower.com> wrote: > >> I have been trying to come up with simple code to let me generate and >> configure ComboBoxes in code. I have succeeded in creating one combo and >> controlling its top and left properties by passing parameters but when I >> try to pass in a name things don't work. Here is the procedures code in a >> file named Try: >> >> * Procedure to create a form >> PROCEDURE CreateForm >> PUBLIC oForm >> oForm = CREATEOBJECT("Form") >> oForm.Caption = "My Form" >> oForm.Show() >> ENDPROC >> >> * Procedure to add a ComboBox to the form >> PROCEDURE AddComboBoxToForm(toForm, nTop, nLeft, cname) >> LOCAL oComboBox >> oComboBox = CREATEOBJECT("ComboBox") >> oComboBox.AddItem("Item 1") >> oComboBox.AddItem("Item 2") >> * toForm.AddObject("oComboBox", (cname)) >> toForm.oComboBox.name = cname >> toForm.oComboBox.Top = nTop >> toForm.oComboBox.Left = nLeft >> toForm.oComboBox.Visible = .T. >> ENDPROC >> >> The code that calls it in a file named Joe follows: >> >> * Call the procedures from the first file >> DO try && load the procedures >> >> * Create a form >> CreateForm() >> >> * Add a ComboBox to the form at position (40, 40) >> AddComboBoxToForm(oForm, 40, 40, "oComboBox1") >> >> * Add a second ComboBox to the form at position (80, 80) >> AddComboBoxToForm(oForm, 80, 80, "oComboBox2") >> >> I have been working with CoPilot to generate the code but it keep telling >> me that I need to create a custom class using the visual tools. I would >> appreciate a second opinion from real experts! >> >> Thanks in advance, >> Joe >> >> >> --- StripMime Report -- processed MIME parts --- >> multipart/alternative >> text/plain (text body -- kept) >> text/html >> --- >> [excessive quoting removed by server] _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: https://leafe.com/archives This message: https://leafe.com/archives/byMID/CAAwxvU=z-q+thybflxs5f3bccn1tbr-kfanzsjisy-8+ajf...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.