[Gambas-user] How can I copy an object

Timothy Marshal-Nichols timothy.marshal-nichols at ...247...
Fri Sep 8 10:40:44 CEST 2006


> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net
> [mailto:gambas-user-bounces at lists.sourceforge.net]On Behalf Of rolf
> Sent: Thursday, 07 September 2006 19:46
> To: mailing list for gambas users
> Subject: [Gambas-user] How can I copy an object
>
>
> Hi your GAMBAS fighter,
>
> I'm still fighting with objects and a question raises to me.
>
> I need a combobox with 5 or 6 entries more then once and have to setup an
> array to manage them. Collect and access the comboboxes in the
> array is no
> problem, but can I create a "sample combobox" with all the wanted
> entries and
> copy this box, of course with a different name and a different
> position into
> the array as offen as needed?
>
> Many thanks for your help.
> Rolf
>

Why swap over complete objects. The ComboBox (like the ListBox) has a List
property that can easily be used to get or update the ComboBox content.

In older versions of Gambas this was a string with each item separated by a
new line. In the latest version of Gambas it is a string array. (There is no
explanation for the change.)

So a better answer is to use the list property. For example:

	Place 3 buttons on a form.
	Give the buttons the tags of  0, 1 and 2 and the group name of
ButtonContent.
	Add a ComboBox and call it ComboBoxContent

Try this code. The first bit just creates the string arrays for the items.
Then swapping over the content is one line.

PRIVATE comboContent AS Object[]

PUBLIC SUB Form_Open()
  DIM i AS Integer
  DIM content AS String[]
  comboContent = NEW Object[3]
  ' Create 3 string arrays for the combo box content
  ' This is for button 1
  content = NEW String[10]
  FOR i = 0 TO content.Count - 1
    content[i] = "Button 1 content " & i
  NEXT
  comboContent[0] = content
  ' This is for button 2
  content = NEW String[24]
  FOR i = 0 TO content.Count - 1
    content[i] = "Button 2 item number " & i
  NEXT
  comboContent[1] = content
  ' This is for button 3
  content = NEW String[4]
  FOR i = 0 TO content.Count - 1
    content[i] = "No much in button 3 # " & i
  NEXT
  comboContent[2] = content
  ' Set the conbo box to button 1 items
  ComboBoxContent.List = comboContent[0]
END

PUBLIC SUB ButtonContent_Click()
  ComboBoxContent.List = comboContent[LAST.Tag]
END

I have attached Gambas projects for versions 1 and 2 of Gambas.

Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ComboBoxArray.G1-0.0.1.tar.gz
Type: application/x-gzip
Size: 4627 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20060908/0a1fad3b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ComboBoxArray.G2-0.0.1.tar.gz
Type: application/x-gzip
Size: 4577 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20060908/0a1fad3b/attachment-0001.bin>


More information about the User mailing list