[Lazarus] Updating a field from an OnEditButtonClick event

Julio César Gázquez julio at mebamutual.com.ar
Mon Jul 4 21:40:53 CEST 2011


El 30/06/11 05:13, Luca Olivetti escribió:
> Al 29/06/2011 17:53, En/na Julio César Gázquez ha escrit:
>
>> However, I found that in the OnEditButtonClick event I can't put the
>> dataset in dsEdit state, the Edit procedure has no visible effect and
>> the field assignment triggers an exception.
>>
>> The same event handler attached to a regular button OnClick event works
>> as intended. The dataset is a Zeos TZQuery, but I'm not sure if this
>> could happen on a different kind of dataset.
>>
>> Is this a known or expected behavior? There is a workaround?
>
> Works here, lazarus 0.9.30, fpc 2.4.2, zeos 6.6.4 (with some local 
> modifications to make it compile under current lazarus).
> (In my program I used a TRxDBGrid, and I'm quite pissed that now the 
> headings are awful, but I also tested with a plain TDbGrid).
>
> FYI, my event handler (the column contains a color):
>
Mine is similar. I even reduced it to

if not (DMAsientosModelo.QueryImputaciones.State in dsWriteModes) then
             DMAsientosModelo.QueryImputaciones.Edit;
          DMAsientosModelo.QueryImputacionescodcuenta.Value:='1';
          DMAsientosModelo.QueryImputacionesdesccuenta.Value:='xxx';

and the problem persisted. It also happens if I disconnect the update 
object and if I disabled cached updates.

Today I tracked it into the FCL (using the CPU Window, I recompiled 
fcl-db as I found in the wiki but I couldn't get the debugger diving 
into the source), and I found:

1)It only happens in the first record of the dataset, in that case Edit 
calls Append.

Procedure TDataset.Edit;

begin
   If State in [dsedit,dsinsert] then exit;
   CheckBrowseMode;
   If Not CanModify then
     DatabaseError(SDatasetReadOnly,Self);
   If FRecordCount = 0 then
     begin
     Append;
     Exit;
     end;

If I fill the first row by hand and use the cell button on the second 
row, it works as intended.

2) The append failed nearly the end of the operation, Appends just wraps 
DoInsertAppend, the State is set to dsInsert but is put back to dsBrowse 
shortly after. I'm not sure exactly where it happens, I'll try to dig 
more tomorrow.


-- 
/Ing. Julio César Gázquez / MEBA - Mutual de Empleados del Banco/ /
                Mitre 923 1º Piso
                0341- 4110533 / 4265010 / 0800 9990452
                S2000COS ROSARIO//
/
*16 resmas = 1 árbol*
Razón suficiente para pensar si es necesario imprimir este correo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110704/5e5e663d/attachment-0002.html>


More information about the Lazarus mailing list