[Gambas-user] Safety for collections

T Lee Davidson t.lee.davidson at gmail.com
Tue Aug 22 18:54:03 CEST 2023


On 8/22/23 07:08, BB wrote:
> There is probably a simple way to do this, damned if I can see how.
> 
> I have a collection of things (datObjects) that have a property (ObjectName::string) that in UML terms are Unique and ID. What I 
> am trying to do is prevent the _replacement_ of an object in the collection if the ObjectName is already there. Better still, 
> I'd like to warn the user when they enter the ObjectName that it already exists.
> 
> The input form has a TextBox for the ObjectName and a "save" button. The latter updates the collection, whose key is the 
> ObjectName, either adding or amending the item in the collection. So I kind of need to do this:
> 
> 1) Are they really trying to add a new item or update an existing one?
> 
> If adding then prevent them from overwriting one with the same ObjectName, otherwise if amending then only allow changes to the 
> other data and not the ObjectName.
> 
> 2) Then update the collection accordingly.
> 
> Is that clear? It isn't to me. Any input would really be appreciated.
> 
> b
> 
> p.s. I am trying to avoid having separate Add and Update buttons for reasons.

Perhaps use a global boolean as a semaphore to indicate if the ObjectName field has been changed (using, of course, the 
TextBox's Change event).

Upon clicking "Save", if the name has been changed, then logic would say the user is attempting to Add a new name. So then check 
to see if the new name already exists and, if so, pop up a form listing similar, existing names so they can create a name that 
does not exist; or simply let them enter a new name and click a "Check" button which would repopulate the form.

The form popped up should have a "Cancel" button that would set the semaphore to False. A successful save should also reset the 
semaphore.


-- 
Lee



More information about the User mailing list