Página 1 de 1

onPreSave event and Update method of tmysql

Publicado: Lun Ene 09, 2012 12:29 am
por Roberto
please, see the fragment code below:
...bla, bla, bla
// customer is a dataset, obviously
customer:OnPreSave := { |oSender| Empty(oSender:Name) }
/*
it means, I guess, that the update process will be stoped if the customer's name is empty, right?
But the update() process returns .T. EVEN if onpresave event says .T.!
The update() returns .F. only if onpresave returns .F. too!
It means that onpresave does not returns lCancel as the documentation says, but lSave...
*/
// some code here to show the form, edit, etc
// the customer_update function will be used to update the dataset
...bla, bla, bla
FUNCTION customer_update(customer)
IF customer:update()
messagebox("saved")
// ok, the datafields are saved and the dataset returns do its normal state
ELSE
messagebox("ops!")
/*
the dataset returns to its normal state and I can't continue modifying the datafields!
So, what do I have to do to keep editing?
*/
ENDIF
RETURN nil
help!

onPreSave event and Update method of tmysql

Publicado: Lun Ene 09, 2012 9:47 am
por ignacio
Roberto escribió el lun, 09 enero 2012 00:29please, see the fragment code below:
...bla, bla, bla
// customer is a dataset, obviously
customer:OnPreSave := { |oSender| Empty(oSender:Name) }
/*
it means, I guess, that the update process will be stoped if the customer's name is empty, right?
But the update() process returns .T. EVEN if onpresave event says .T.!
The update() returns .F. only if onpresave returns .F. too!
It means that onpresave does not returns lCancel as the documentation says, but lSave...
*/
// some code here to show the form, edit, etc
// the customer_update function will be used to update the dataset
...bla, bla, bla
FUNCTION customer_update(customer)
IF customer:update()
messagebox("saved")
// ok, the datafields are saved and the dataset returns do its normal state
ELSE
messagebox("ops!")
/*
the dataset returns to its normal state and I can't continue modifying the datafields!
So, what do I have to do to keep editing?
*/
ENDIF
RETURN nil
help!
The event OnPreSave should return FALSE when you want to stop the update process. So, your code should be like this I believe:
customer:OnPreSave := { |oSender| .NOT. Empty(oSender:Name) }
Regards,

onPreSave event and Update method of tmysql

Publicado: Lun Ene 09, 2012 3:05 pm
por Roberto
Ignacio,
Yes, but it isn't what the documentation says.
The second point is: what to do if the update returns false? I lost the datafield's text and I can't continue editing. It's not the expected behavior, I guess.

onPreSave event and Update method of tmysql

Publicado: Lun Ene 09, 2012 5:24 pm
por ignacio
Roberto escribió el lun, 09 enero 2012 15:05Ignacio,
Yes, but it isn't what the documentation says.
The second point is: what to do if the update returns false? I lost the datafield's text and I can't continue editing. It's not the expected behavior, I guess.

Sorry, surely my English is not as good as yours. Could you give us a better translation for us. TIA.
If the event OnPreSave returns false, the Update process is completely canceled. If you want to continue in Edit mode you can overload the TDataset:Update() method and comment line 543. Maybe you are right and this line should be completely deleted but we have to check it deeply so we do not break anyone code.
Dataset events were designed to be used on the controller part of your application with no interaction with the visual parts, and that is the reason why the edition process is completely stopped.
Regards,

Attached files

onPreSave event and Update method of tmysql

Publicado: Lun Ene 09, 2012 8:13 pm
por Roberto
Thank you indeed