Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-06

Updating a field from an OnEditButtonClick event

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Julio César Gázquez

Hi list.

I'm using a TDBGrid component, with an OnEditButtonClick event, and a visible button for the first (code) column. In the event handler I open a search dialog, then I want to edit the dataset row and set the column value and also other value (that is, code and description as found in the search).

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?

Regards...

/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.freepascal.org/pipermail/lazarus/attachments/20110629/75d7b845/attachment.html>

Reply by email

Luca Olivetti
to Julio César Gázquez

Al 29/06/2011 17:53, En/na Julio C?sar G?zquez ha escrit:

Show quoted text 9 lines
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):

procedure TMainForm.GridPantallasEditButtonClick(Sender: TObject);
var
   f:TLongintField;
begin
   if copy(GridPantallas.SelectedField.FieldName,1,6)='color_' then
   begin
     f:=TLongintField(GridPantallas.SelectedField);
     ColorDialog1.Color:=f.value;
     if ColorDialog1.Execute and (ColorDialog1.Colorf.value) then
     begin
       if not (QueryPantallas.State in dsWriteModes) then
         QueryPantallas.Edit;
       f.value:=ColorDialog1.Color;
       PruebaColor;
     end;
   end;
end;

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es Tel. +34 935883004 (Ext.133) Fax +34 935883007

Reply by email

Julio César Gázquez
to Luca Olivetti

El 30/06/11 05:13, Luca Olivetti escribi?:

Show quoted text 19 lines
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.freepascal.org/pipermail/lazarus/attachments/20110704/5e5e663d/attachment-0001.html>

Reply by email

Julio César Gázquez
to Luca Olivetti: Al 29/06/2011 17:53, En/na Julio C?sar G?zquez ha escrit: Works here, lazarus 0.9.30, fpc…

El 30/06/11 05:13, Luca Olivetti escribi?:

Show quoted text 10 lines
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. > 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).

I've built again fcl-db with debugging symbols and find the problems lie on datasource code triggered when the dataset propagates the event in the append code. If I detach the datasource before calling Edit it works as intended.

BTW, I'm using fpc 2.4.4 from a recent build of 0.9.30+fixes, could it be a regression?

/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.freepascal.org/pipermail/lazarus/attachments/20110707/fb2d91d7/attachment.html>

Reply by email

Luca Olivetti
to Julio César Gázquez

Al 07/07/2011 14:56, En/na Julio C?sar G?zquez ha escrit:

Show quoted text 7 lines
I've built again fcl-db with debugging symbols and find the problems lie on datasource code triggered when the dataset propagates the event in the append code. If I detach the datasource before calling Edit it works as intended. BTW, I'm using fpc 2.4.4 from a recent build of 0.9.30+fixes, could it be a regression?

I cannot say: I don't see this bug because I never hit the event handler with an empty dataset (i.e., I only enable it with an existing record).

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es Tel. +34 935883004 (Ext.133) Fax +34 935883007

Reply by email