Jump to content

Adding Second DB Record Results In Blank Record Shown


Frederick

Recommended Posts

I use PostgreSQL as my database backend and in my application, I allow the user to add records continuously until they decide to stop.

When the form is shown for the first time after the add request is initiated, a procedure called AddRecord is called and it contains the following code.

procedure TMainForm.AddRecord;
begin
   oQry.Append;
   oQry.FieldByName('code').AsString:='*CODE';
   oQry.FieldByName('name').AsString:='Name';
   oQry.FieldByName('pricemonth').AsFloat:=0.00;
   oQry.FieldByName('priceyear').AsFloat:=0.00;
   oQry.FieldByName('priceonetime').AsFloat:=0.00;
   oQry.FieldByName('priceupdate').AsFloat:=0.00;
end;

Once the user clicks the Save button, the following code is called.

procedure TMainForm.SaveRecord;
begin
   oQry.Post;
   addrecord;
   Field1.Setfocus;
end;

and the cycle repeats.

In a VCL application, as the first and second records are appended, you can see all the field content in the TDBGrid on the left, as well as in the individual TDBEdit components.

In a UniGUI application, the record content for the first append is shown normally in the TUniGrid and the TUniDBEdit components. However, after the Save button is clicked, the second append results in blank content as shown in the TUniGrid and TUniDBEdit components.

Why is this?

--
Frederick
(UniGUI Complete - Professional Edition 1.90.0.1504)

Adding DB Records Via VCL App.gif

Adding DB Records Via UniGUI App.gif

Link to comment
Share on other sites

  • 2 weeks later...

I previously submitted this post but it seems to have fallen between the cracks.

Can someone from technical support please take a look at this problem?

I am attaching an animated GIF of the same problem with a SQLite database. Let me know if you need a test case file.

Add Second Record Results In Blank Display.gif

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...
  • Administrators

Problem here is that Grid needs to reload rows after each Append/Post. This causes to loose the last appended row data which are not posted yet.

To resolve this issue you must use OnNewRecord event of your dataset as below:

procedure TMyForm2.qryNewRecord(DataSet: TDataSet);
var
   nNextno : Integer;
begin
   oQrynextno.Close;
   oQrynextno.Open;
   nNextno:=oQrynextno.fieldbyname('nextno').asInteger;
   oQrynextno.Close;
   with DataSet do
   begin
      fieldbyname('id').AsInteger:=nNextno;
      fieldbyname('compname').asString:='*New Compname';
      fieldbyname('model').asString:='*New Model';

   end;
end;

 

also:

procedure TMyForm2.AddRecord;
begin
   with oQry do begin
      append;
   end;
end;

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...