Master Detail

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
John Bell
Posts: 17
Joined: Mon 25 Sep 2006 17:38

Master Detail

Post by John Bell » Wed 04 Dec 2013 22:58

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

AndreyZ

Re: Master Detail

Post by AndreyZ » Thu 05 Dec 2013 11:33

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;

John Bell
Posts: 17
Joined: Mon 25 Sep 2006 17:38

Re: Master Detail

Post by John Bell » Thu 05 Dec 2013 22:15

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.

John Bell
Posts: 17
Joined: Mon 25 Sep 2006 17:38

Re: Master Detail

Post by John Bell » Thu 05 Dec 2013 22:47

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

Post by AndreyZ » Fri 06 Dec 2013 06:25

I am glad you have found the solution. If any other questions come up, please contact us.

John Bell
Posts: 17
Joined: Mon 25 Sep 2006 17:38

Re: Master Detail

Post by John Bell » Fri 06 Dec 2013 23:11

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

Post by AndreyZ » Mon 09 Dec 2013 10:55

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.

Post Reply