“删除 TFDMemTable NestedDataSet 记录时为什么会出现错误“未找到书签”?”

huangapple go评论55阅读模式
英文:

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&lt;TDataSetField*&gt;(aDataSet-&gt;FieldByName(&quot;keywords&quot;));
	if (keywordsField)
	{
		TDataSet* keywordsDataSet = keywordsField-&gt;NestedDataSet;
		TField*   keywordField    = keywordsDataSet-&gt;FieldByName(&quot;keyword&quot;);
		keywordsDataSet-&gt;First();
		while (!keywordsDataSet-&gt;Eof)
		{
			keywordsDataSet-&gt;Delete();
		}
	}

However, when the ->Delete() executes, I get an error message:

Exception class EFDException with message &#39;[FireDAC][Comp][DS]-200.  Bookmark is not found for dataset [TFDCustomMemTable()]&#39;

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.

huangapple
  • 本文由 发表于 2023年4月17日 11:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定