In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

onPreSave event and Update method of tmysql

Xailer professional forum in English
Responder
Roberto
Mensajes: 177
Registrado: Mar Oct 16, 2007 11:53 pm

onPreSave event and Update method of tmysql

Mensaje 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!
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9447
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

onPreSave event and Update method of tmysql

Mensaje 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,
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Roberto
Mensajes: 177
Registrado: Mar Oct 16, 2007 11:53 pm

onPreSave event and Update method of tmysql

Mensaje 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.
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9447
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

onPreSave event and Update method of tmysql

Mensaje 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
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Roberto
Mensajes: 177
Registrado: Mar Oct 16, 2007 11:53 pm

onPreSave event and Update method of tmysql

Mensaje por Roberto »

Thank you indeed
Responder