#1 2022-10-10 15:21:44

dka1
Member
From: Greece
Registered: 2017-07-25
Posts: 28

problem with TDocVariantData.SearchItemByValue and varOleStr

Hello AB,
using TDocVariantData.SearchItemByValue with values string (varOleStr)
I get error "Could not convert variant of type (OleStr) into type (Double)"
When debug I see function SortDynArrayVariantComp compare as string "CMP" only when value is type varString, all other values compared as "ICMP"
I change code as bellow and work, but I do not know if it safe (what if value type is any)
Can you check it please?

function SortDynArrayVariantComp(const A,B: TVarData; caseInsensitive: boolean): integer;
 ...
  if (AT<=varNull) or (BT<=varNull) then
    result := ord(AT>varNull)-ord(BT>varNull) else
[ins]  if (AT = varOleStr) or (BT = varOleStr) or (AT = varString) or (BT = varString) then
    result := CMP[caseInsensitive](variant(A),variant(B))
  else
    result := ICMP[VarCompareValue(variant(A),variant(B))][/ins]
[del]{  if (AT<varString) and (BT<varString) then
    result := ICMP[VarCompareValue(variant(A),variant(B))] else
    result := CMP[caseInsensitive](variant(A),variant(B));}[/del]
end;

Offline

#2 2022-10-10 16:08:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: problem with TDocVariantData.SearchItemByValue and varOleStr

What are AT and BT values in your case?

Offline

#3 2022-10-10 16:18:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: problem with TDocVariantData.SearchItemByValue and varOleStr

Please try https://synopse.info/fossil/info/a37bab0324

I used mORMot 2 code as reference, which seems more correct here - and also faster.

Offline

#4 2022-10-12 08:24:45

dka1
Member
From: Greece
Registered: 2017-07-25
Posts: 28

Re: problem with TDocVariantData.SearchItemByValue and varOleStr

It works ,
thank you AB.

Offline

Board footer

Powered by FluxBB