Delphi: Error "Invalid field type" with basic / verbose datasets

I asked about setting up an in-memory dataset using TClientDataset and was told that I needed to use the Create Dataset command in the form designer. This works fine until I try to create a master-detail database relationship. If I have a def field of type ftDataSet, then running the Create Data Set command (or calling a method at runtime) gives an "Invalid field type" error. I did some searches and found that other people have had this problem before, but no one ever comes up with an answer. Does anyone know how to fix this?

+1


source to share


3 answers


Instead of putting your data in the ftDataSet column, just use a unique integer or GUID for the key reference and put the details in another TClientDataSet and get that key. As with a regular database. Each TClientDataSet represents a different table.



+3


source


If you create a field of type ftDataSet, you need to define a dataset, otherwise the type is invalid.

You can define a dataset using:



  • select a field.
  • select the ChildDefs property and click the [...] button.
  • add fields.

Now you can create a dataset. If one of the children is not of type ftDataSet, then you have to recursively repeat this process.

+1


source


Disgusting problem that cost me a lot of time. Finally, I found the workaround described here (thank you guys!):

http://www.delphigroups.info/3/6/171869.html

Summary: The culprit is the primary client dataset field definitions, that is, those that contain ftDataset fields. Once the field definitions of the master dataset are not empty, the CreateDataSet command will fail with the above error message ("Invalid field type").

Workaround: Create master part tables according to the instructions, but make sure the field definitions are empty when creating CreateDataset:

a) Design time: before you execute "master dataset | RightClick | Create DataSet" in the project form, you need to click on the master dataset, go to the object inspector, click "FieldDefs" and delete all fields in the FieldDefs window. (The first time you built the underlying dataset, it still isn't there, but later it is.) Only then create the dataset. (I've tried this myself with Delphi 2007, it works.)

b) Runtime: Call [Name of Masterdataset] .FieldDefs.Clear before you [Name of Masterdataset] .CreateDataSet. (I haven't tried this myself, but it's reliably documented in the above link.)

If it was too difficult, check out the link above.

+1


source







All Articles