Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Inserting record into an empty dataset

 Post Reply Post Reply
Author
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Topic: Inserting record into an empty dataset
    Posted: 31 Mar 2020 at 12:40pm
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?

Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 9194
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 31 Mar 2020 at 9:32pm
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?
Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2020 at 3:03pm
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
empty dataset
Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 9194
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2020 at 5:33pm
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?
Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2020 at 6:43pm
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:

Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2020 at 6:44pm
The apps not so big at the moment so I could zip it up and send it across if that helps
Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 03 Apr 2020 at 3:25pm
Any thoughts on this yet? I'm stuck until I sort it.
Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 9194
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 03 Apr 2020 at 3:44pm
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 ....
Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 04 Apr 2020 at 4:20pm
Ok, will send it across later
Back to Top
Weetch Russell View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2012
Posts: 199
Post Options Post Options   Quote Weetch Russell Quote  Post ReplyReply Direct Link To This Post Posted: 06 Apr 2020 at 5:52pm
sorry for teh delay, that's been sent
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down