Inserting record into an empty dataset

My app has a main form and a datamodule. Secondary forms are rendered into a TWebPanel and editing forms are presented as pop ups. I have 

- MainForm: a TWebGrid which lists Companies with a TWebDataSource on the form linked to the Company TXDataWebDataset on the DataModule. 

-  Embedded TWebForm which contains a TWebGrid which lists employees with a TWebDataSource on the form linked to the Employee TXDataWebDataset on the DataModule. It has a button for editing and one for adding.
- Popup TWebForm for editing employees. The fields are linked to the Employee TXDataWebDataset on the DataModule with a TWebDataSource on the pop up form.

If I click the Add button when the employee dataset contains records all all is fine. A new record displays in the Employee grid and the popup form allows editing this record.

If the Add button is clicked when the Employee dataset is empty the new record displays in the grid, but is not reflected in the controls on the popup form. I've tested this by assigning some values on the dataset.OnNewRecord event.

I have tried inserting the record at different stages of the process. I have tried passing the datasource in from the Employee Grid form, rather than have the popup form use it's own datasource, but nothing seems to work.

Any ideas?

Not sure I fully understand the scope of what you try to do.
Do you open this popup AFTER you insert a new record or is this popup kept open during the insert?
What kind of DB-aware controls are on this popup form? When you put these controls on the main form, are the changes in the dataset always reflected?

I have tried inserting the record 

  • before creating the form
  • in the OnCreate event of the form
  • in a method provided in the createnew constructor
The DB Aware controls are TWebDBEdit and a TWebDBComboBox

If I put a control on the calling form, linked to the same DataSource as the TwebDBGrid it behaves the same way as the ones on the popup (i.e. only shows data if there are already records in the dataset.

The first image shows adding a record when there are already records in the dataset, the second when the dataset is empty. The text "First Name" is added on the dataset OnNewRecord event.

populated dataset


Empty Dataset


It is unclear what is causing this.
If you add a small debugging code in the popup form to loop through the datasource.Dataset, do you see records with proper values when checking these?

Added a button to the popup form and that gives the expected values. The debug code:


 'DataSource.Name=' + PersonSource.Name  + #10 +
  'FirstName.Datasource=' + FirstName.DataSource.Name + #10 +
  'FirstName.DataField=' + FirstName.DataField  + #10 +
  'FirstName.Dataset.Value=' + FirstName.DataSource.DataSet.FieldByName(FirstName.DataField).AsString + #10 +
  'Dataset.Name=' + PersonSource.DataSet.Name + #10 +
  'Dataset.State=' + cState[PersonSource.DataSet.State] + #10 +
  'RecNo =' + IntToStr(PersonSource.Dataset.RecNo) + #10 +
  'FirstName=' + PersonSource.DataSet.FieldByName('FirstName').asString;


The output:


The apps not so big at the moment so I could zip it up and send it across if that helps

Any thoughts on this yet? I'm stuck until I sort it.

We could not yet allocate the needed time to create a project ourselves with all these details to try to reproduce this. If we would have received a project with source to reproduce ....

Ok, will send it across later

sorry for teh delay, that's been sent

I've same problem . In the detail form i'm Inserting a record in the formcreate event but DM0.wdROrdNewRecord in the datamodule don't fire in this event only if i press a button to insert a record after form show ! How solve it ?

SOLVED : using Append go fine BUT Insert give error must be corrected !

1 Like