英文:
why do I get the error "Bookmark is not found" when deleting a record from a TFDMemTable NestedDataSet?
问题
I have a TFDMemTable with a NestedDataSet field named "keywords", which has a single field within the nested dataset named "keyword".
To create that TFDMemTable with those fields, I do not use any persistent fields, but rather FieldDefs, with the appropriate field of type ftDataSet and a ChildDefs containing a single ftString named "keyword".
When I did use persistent fields, even with FieldDefs also present, the FieldDefs were not respected. Another solution is to use persistent fields, and create a second TFDMemTable with the single "keyword" field, and point the DataSetField property of the child TFDMemTable to the "keywords" ftDataSet field in the outer DataSet.
The problem comes when I want to remove the existing records in the NestedDataSet. I use a simple loop:
TDataSetField* keywordsField = dynamic_cast<TDataSetField*>(aDataSet->FieldByName("keywords"));
if (keywordsField)
{
TDataSet* keywordsDataSet = keywordsField->NestedDataSet;
TField* keywordField = keywordsDataSet->FieldByName("keyword");
keywordsDataSet->First();
while (!keywordsDataSet->Eof)
{
keywordsDataSet->Delete();
}
}
However, when the ->Delete() executes, I get an error message:
Exception class EFDException with message '[FireDAC][Comp][DS]-200. Bookmark is not found for dataset [TFDCustomMemTable()]'
That seems strange, because I am not using any bookmarks in my code.
Any idea what is going on?
英文:
I have a TFDMemTable with a NestedDataSet field named "keywords", which has a single field within the nested dataset named "keyword".
To create that TFDMemTable with those fields, I do not use any persistent fields, but rather FieldDefs, with the appropriate field of type ftDataSet and a ChildDefs containing a single ftString named "keyword".
When I did use persistent fields, even with FieldDefs also present, the FieldDefs were not respected. Another solution is to use persistent fields, and create a second TFDMemTable with the single "keyword" field, and point the DataSetField property of the child TFDMemTable to the "keywords" ftDataSet field in the outer DataSet.
The problem comes when I want to remove the existing records in the NestedDataSet. I use a simple loop:
TDataSetField* keywordsField = dynamic_cast<TDataSetField*>(aDataSet->FieldByName("keywords"));
if (keywordsField)
{
TDataSet* keywordsDataSet = keywordsField->NestedDataSet;
TField* keywordField = keywordsDataSet->FieldByName("keyword");
keywordsDataSet->First();
while (!keywordsDataSet->Eof)
{
keywordsDataSet->Delete();
}
}
However, when the ->Delete() executes, I get an error message:
Exception class EFDException with message '[FireDAC][Comp][DS]-200. Bookmark is not found for dataset [TFDCustomMemTable()]'
That seems strange, because I am not using any bookmarks in my code.
Any idea what is going on?
答案1
得分: 0
After a number of dead ends (including trying the EmptyTable() method, which caused other problems), I reviewed the sample code, and realized that I had not set the outer dataset to the Edit state.
Ensuring that the outer dataset was in the Edit state resolved this problem, and resolved a similar problem I had when I tried adding records to the nested dataset, using Append() and Post() on the nested dataset. In that case as well, the outer dataset (aDataSet in the code above) must be in Edit state.
Because this error message was not found when I searched for it, and because it is not intuitive that an error about bookmarks would be raised because a dataset is not in edit state, I decided to post this.
英文:
After a number of dead ends (including trying the EmptyTable() method, which caused other problems), I reviewed the sample code, and realized that I had not set the outer dataset to the Edit state.
Ensuring that the outer dataset was in the Edit state resolved this problem, and resolved a similar problem I had when I tried adding records to the nested dataset, using Append() and Post() on the nested dataset. In that case as well, the outer dataset (aDataSet in the code above) must be in Edit state.
Because this error message was not found when I searched for it, and because it is not intuitive that an error about bookmarks would be raised because a dataset is not in edit state, I decided to post this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论