Entity Changed Event Does not complete

Posts   
 
    
Posts: 34
Joined: 03-Oct-2005
# Posted on: 05-Dec-2005 14:02:00   

Hi

I have the following problem. I have an Entity with a datetime field, which is editied on a WinForms form with a datetimepicker control bound to the field.

The first time the entity is edited is retrieved from the db, passed to the form, which is displayed and everythings works as it should.

If the entity is edited for a second time the initial copy is retrieved from a collection, passed to the form again, and that is when the problems start.

Setting the datetime value to a valid value results in the value being passed to


Public Overridable Property [InceptTime]() As System.DateTime

This calls


SetNewFieldValue(CType(PurchaseFieldIndex.InceptTime, Integer), value)

calls


Dim toReturn As Boolean = MyBase.SetNewFieldValue (fieldIndex, value, False)

returns true

and goes to


Case PurchaseFieldIndex.InceptTime
    OnInceptTimeChanged()

which calls


RaiseEvent InceptTimeChanged(Me, New EventArgs())

which never returns.

No exception is raised, and the control will not let me tab away from it, suggesting an invalid value...

Any ideas as this is now really bugging me....

Posts: 34
Joined: 03-Oct-2005
# Posted on: 05-Dec-2005 14:07:58   

More info - it IS raising an exception

"'01/01/0001 00:00:00' is not a valid value for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'."

Where has my date value gone - ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Dec-2005 14:42:10   

Hello,

The first time the entity is edited is retrieved from the db, passed to the form, which is displayed and everythings works as it should.

Do you mean that when the entity is edited for the first time, it is saved first in the database, then retrieved and displayed correctly (the new values are displayed)?

If the entity is edited for a second time the initial copy is retrieved from a collection, passed to the form again, and that is when the problems start.

What initial value?! Do you mean when you retrieve that entity in order to edit it?!!

Setting the datetime value to a valid value results in the value being passed to

Does the problem happen when you retrieve the saved values or when you save the new ones?

One filan question (sorry for the long list of question, but I'm trying to understand what's happenning):

Could you please send us the stack trace of the exception?

Posts: 34
Joined: 03-Oct-2005
# Posted on: 05-Dec-2005 15:22:15   

Walaa wrote:

Hello,

The first time the entity is edited is retrieved from the db, passed to the form, which is displayed and everythings works as it should.

Do you mean that when the entity is edited for the first time, it is saved first in the database, then retrieved and displayed correctly (the new values are displayed)?

If the entity is edited for a second time the initial copy is retrieved from a collection, passed to the form again, and that is when the problems start.

What initial value?! Do you mean when you retrieve that entity in order to edit it?!!

Setting the datetime value to a valid value results in the value being passed to

Does the problem happen when you retrieve the saved values or when you save the new ones?

One filan question (sorry for the long list of question, but I'm trying to understand what's happenning):

Could you please send us the stack trace of the exception?

No, when the entity is edited for the first time it is not saved to the DB, it is cached in a collection. The new values are read correctly from it at this point. When it is edited a second time it is the initial instance (that has been edited once already) that is retrieved from the collection

The problem does not happen when the enity is saved, but when the datetimepicker tries to apply the date on the second edit.

Stack Trace....

" at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at System.Windows.Forms.Binding.SetPropValue(Object value) at System.Windows.Forms.Binding.PushData() at System.Windows.Forms.BindingManagerBase.PushData() at System.Windows.Forms.PropertyManager.OnCurrentChanged(EventArgs ea) at System.Windows.Forms.BindToObject.PropValueChanged(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at CallUK.ObjectLayer.EntityClasses.PurchaseEntity.OnInceptTimeChanged() in D:\Development\API\ObjectLayer\DatabaseGeneric\EntityClasses\PurchaseEntity.vb:line 380"

Hope this is of some use...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Dec-2005 16:17:57   

Do you manually bind to events of the entity in the form? Because this is what happens: Form F, Entity E. E has an event, E.Event and F binds to that event with a handler: F.EEventHandler.

When you manually add the event handler, like: e.Event += new EventHandler(EEventHandler);

and you're done with the form, it goes out of scope. However the form isn't cleaned up by the garbage collector because E.Event points to F.EEventHandler and thus keeps F in memory.

Raising E.Event will then also end up in F.EEventHandler, and if that's a method which waits for user input, you can wait till oblivion.

If you run in the debugger, and you experience the hang on the raiseevent, could you press the pause button on the debug toolbar, to see where it hangs?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 34
Joined: 03-Oct-2005
# Posted on: 05-Dec-2005 16:50:56   

I think you're on to something. Although not waiting for user input (it is happening on a control_Validate event) - i think it is the original instance of the form that is causing the problem.

I put together a quick test app to test this - when an instance of the entity is passed back to the original instance of the form everything works as expected, when passed to a new instance of the form the problem re-occurs

I took this route as a I am a long time VB6 programmer, and it was always easier to have a new instance of an edit form to avoid having to clear data from an existing instance. I'll have to have a play with this, it may be that the databinding will take care of all of that for me.

Thanks (again) for your support.

Matt