S sconlon Active Member Licensed User Longtime User May 21, 2013 #1 I have defined a custom type 'menuitem' and dimed a global as this type Code: Type menuItem (ID As Int, category As String, item As String, description As String, price As String, qty as Int, options As String, optionCode As String) dim gItem as menuitem The app lists menu items (as in food) and the user can select one and add it to their order. When an item is selected I load its values into gItem and then add it to the order which is a list (orderlist) of menuitems Code: orderlist.add(gItem) I believe this only adds a pointer to gItem into the list so that if I subsequently change one of the values of gItem (without adding any further items to the list) the item in the list will change. Since I process gItem within various subs I need it as a global so how can I add it to the list and not have the problem when it is subsequently changed. I don't know if I have explained the issue well enough but I imagine that it is common enough and there must be some way of overcoming it.
I have defined a custom type 'menuitem' and dimed a global as this type Code: Type menuItem (ID As Int, category As String, item As String, description As String, price As String, qty as Int, options As String, optionCode As String) dim gItem as menuitem The app lists menu items (as in food) and the user can select one and add it to their order. When an item is selected I load its values into gItem and then add it to the order which is a list (orderlist) of menuitems Code: orderlist.add(gItem) I believe this only adds a pointer to gItem into the list so that if I subsequently change one of the values of gItem (without adding any further items to the list) the item in the list will change. Since I process gItem within various subs I need it as a global so how can I add it to the list and not have the problem when it is subsequently changed. I don't know if I have explained the issue well enough but I imagine that it is common enough and there must be some way of overcoming it.
Erel B4X founder Staff member Licensed User Longtime User May 21, 2013 #2 You can create a Clone sub that returns a copy of the original item. This way the original item will not be modified. Upvote 0
You can create a Clone sub that returns a copy of the original item. This way the original item will not be modified.
S sconlon Active Member Licensed User Longtime User May 21, 2013 #3 Thanks Erel. I am already using a keyStoreFile so would writing it to that and then getting it back do the trick? Upvote 0
Thanks Erel. I am already using a keyStoreFile so would writing it to that and then getting it back do the trick?