[Gambas-user] Safety for collections

BB adamnt42 at gmail.com
Thu Aug 24 14:25:33 CEST 2023


> On 22/8/23 8:38 pm, 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.
>>
> I may have oversimplified. The basic gen is that there is a form with 
> a list of some type on the left and an "editor" panel on the right. 
> The user clicks on an item in the list and the data for that item is 
> loaded in the editor. Now the quick way for them to add a new item is 
> to click on a similar one, give it a new name and change some of the 
> other data as required, then click the save button. BUT the new name 
> they use may already exist. ... ...

Thanks everyone for their inputs.

This is, in the end, not simple at all. Lee's idea is what I'm following 
at the moment. However, there are problems (or issues or complexities..) 
Here's one:

_Usecase_

1. User clicks on an item in the list. System loads and displays the 
related object in the editor form.

2. User changes the object name and does nothing else.

3. (While focus is still on the name textbox or even after stuffing 
around in other editor controls and then shifting back) User presses Ctl+Z

---> The text reverts to the original but the "changed" indicator is 
still set to true.

This gets even worse when they do repeated changes and undos.


I guess what I'm really looking for is a "isDirty" algorithm/structure 
that when the save is attempted /somehow/ works out what their intention 
is .. add a newy, change the original or /change another one that 
exists/ while preventing them from overwriting something inadvertently.

Here's the damn restrictions.
I cant change the code in the parent form, but I could override the save 
button method /somehow/.
I can't _easily_ change the underlying class for the object.

So everything needs to happen inside the editor form.

grrrrrrraaarrrgh

b

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230824/e90483cb/attachment-0001.htm>


More information about the User mailing list