by cdshearer >> Thu, 30 May 2002 3:45:18 GMT
Hi all
I came up with this tip today to this problem that has bothered me for years! I don't know whether anybody else has come up with a solution for this - certainly not that I've encountered.
Anyway, often you have a ListBox control on a form with a collection attached to it using the listCollection method. You allow the user to create a new object, which is destined to appear in the list, via JADE's notification mechanism, and you'd like to select the object in the list.
To solve this, you might try the following...
begin
Transaction;
create = customer;
customer.setDetails(....);
commitTransaction;
lstCustomer.listObject := customer;
However, this causes an Invalid Property Value (14008) exception as the new Customer object won't be in the ListBox until it processes the update notification from the collection. So, it is seemingly impossible to get the newly created Customer object selected in the ListBox.
Then I had the idea that the ListBox control must be processing a notification when the collection is updated. So, I added a sysNotifiy method to my subclassed ListBox control and sure enough, it got called when I created my new Customer object.
So, the idea is to record the desired selected object on the ListBox control, then when it receives the sysNotify event, select the object as the listObject.
Here's what I did. Note you will need to subclass the ListBox class to use this technique.
1. Add a public selectObject reference of type Object.
2. Add the following sysNotify method:
sysNotify(listbox: ListBox input; eventType: Integer; theObject: Object; eventTag: Integer) updating;
begin
inheritMethod(listbox, eventType, theObject, eventTag);
if selectObject <> null = then
// attempt to select the object, which may now be in the list
on Exception do ignoreInvalidPropertyValueEx(exception);
listObject := selectObject;
selectObject := null;
endif;
end;
This also makes use of an exception handler - in case the object isn't actually in the list.
3. Add the following exception handler code:
ignoreInvalidPropertyValueEx(pEx: Exception): Integer protected;
begin
if pEx.errorCode = 14008 then
return Ex_Resume_Next;
else
return Ex_Pass_Back;
endif;
end;
So, now the code can be modified as follows:
begin
Transaction;
create = customer;
customer.setDetails(....);
commitTransaction;
lstCustomer.selectObject := customer;
Hope this helps somebody...
Craig Shearer