In the SetTag function, the tags are incorrectly deleted if the sequence tag was not sorted, that tag already exists, and the ReplaceIfExist flag is true.
idx := -1; // this is the start
if fSorted then // is false for sequences i.e. nested DICOM groups
...
if idx > -1 then // we won't go in here because idx is still -1
begin
...
else
begin
// append to the end
idx := fTags.Add(tag); // we'll hit this code, so idx will be > 0, as the same tag already exists
end;
// at this point, we have at least 2 identical tags, the old one and the new one.
if ReplaceIfExist then
begin
// remove possible other replications
i := 0;
while i < fTags.Count do
begin
if (PIEDicomTag(fTags[i])^.Group = Tag^.Group) and (PIEDicomTag(fTags[i])^.Element = Tag^.Element) and (i <> idx) then
DeleteTag(i) // the old tag will be deleted, which is correct, but because i is not incremented, the new tag will also be deleted as i <> idx (of the new tag)
else
inc(i);
end;
end;
For now, I've just set the sorted flag to true, though I would prefer not to do that.
Thanks.
Ray