I am sure i will feel like an idiot tomorrow but i have an entry form and upon opening it, i set all the detail tables' mastersource and masterfields (master and detail are linked by one field - id which has the same name). i use AddWhere for all the details ('Id = :Id'). i open the master table then i open the detail tables. i can scroll through the table and the detail tables show up correctly. i can edit existing rows in the detail tables. However, i cannot really insert a new record in the detail tables as the Id is not filled in so depending on the structure of the detail i get an error or a 0 (default value) in the detail table Id field. Any ideas of what i am doing wrong? thanks.
I am using W7-64, Delphi XE3 and MyDAC 8.1.4
Master Detail
-
AndreyZ
Re: Master Detail
Please try setting the RefreshParamsOnInsert global variable (that is declared in the MemDS unit) to True and check if the problem persists. For this, you should use the following code in one of the units of your application:
Code: Select all
initialization
RefreshParamsOnInsert := True;
Re: Master Detail
That did not work. What i had to do was fill in the DetailFields value and that solved the problem. FWIW, i had the master and detail table on a datamodule and when i opened the data entry form, i set the master source and the master fields, added the WHere clause to the detail sql and then opened the tables in the appropriate order. Also, the application was migrated from the BDE using your wizard. anyway, thanks for your quick response.
Re: Master Detail
if it helps, i "figured" it out by configuring the master detail in the IDE and when that worked, went back to configuring in the code and, all of a sudden, that also worked. Looked at the history in the test project and noticed the difference between the working and non-working was the detailfields value.
-
AndreyZ
Re: Master Detail
I am glad you have found the solution. If any other questions come up, please contact us.
Re: Master Detail
One thing i would suggest would be to change your example on how to set up the Master Detail relationship to include setting the DetailFields.
-
AndreyZ
Re: Master Detail
There are two ways of establishing master/detail relationship: using parameters, and using the MasterFields and DetailFields properties. When using parameters, you should leave the DetailFields property blank. You can find descriptions and examples of both ways at http://www.devart.com/mydac/docs/work_md.htm
MyDAC demo project demonstrates usage of both approaches.
MyDAC demo project demonstrates usage of both approaches.