You are not logged in.
Pages: 1
Hi
I'm getting an error when working with TDocVariantData.
// This code works
procedure TForm1.Button3Click(Sender: TObject);
var
LObj:TDocVariantData;
LKey, LValue:Utf8String;
begin
LKey:='id';
LValue:='1001-test;@6f2dcdcc4303a085a18d98419e1fb374';
LObj.AddValue(LKey, LValue);
LKey:='id2';
LValue:='50';
LObj.AddValue(LKey, LValue);
memo1.Lines.Add(LObj.ToJson);
end;
// This code is not working
procedure TForm1.Button2Click(Sender: TObject);
var
LObj:TDocVariantData;
begin
FillParams(PUtf8Char(FParamStr), LObj);
memo1.Lines.Add(LObj.ToJson);
end;
procedure FillParams(AParams:PUtf8Char; var AObj:TDocVariantData);
var
LKey, LValue:Utf8String;
begin
if (AParams = nil) then exit;
repeat
AParams := UrlDecodeNextNameValue(AParams, LKey, LValue);
// Lkey='id', LValue='1001-test;@6f2dcdcc4303a085a18d98419e1fb374'
AObj.AddValue(LKey, LValue); <--- Range check error
if AParams = nil then break;
until AParams^ = #0;
end;
Why am I getting this error? Am I missing something?
Last edited by nakisen (2024-05-11 21:22:45)
Offline
Interestingly, even though I haven't made any changes in the code, sometimes I get the "Range check error" error and sometimes the "Add: Unexpected [id] object property in an array" error.
Compiler/IDE: Delphi 12.
Offline
I did initialization and everything is fine
LObj.Init;
Offline
I started using "IDocList/IDocObject". How can I do custom filtering using TVariantCompare? Are there any examples? I need to make a comparison like "startsWith/endsWith" or "%like%".
Offline
TVariantCompare is to compare... variants... so to compare values, e.g. in a IDocList.
Is it what you cant to do?
Then you need to work with a custom comparison function.
function MyCompare(const V1, V2: variant): PtrInt;
var u1, u2: RawUtf8;
begin
VariantToUtf8(V1, u1);
VariantToUtf8(V2, u2);
if .... then // put the comparison between u1 and u2 here
result := 0 // match (=coEqualTo)
else
result := 1; // not match
end;
Then use this compare=MyCompare and match=coEqualTo for the IDocList.Filter() method parameters.
As an alternative, you can use the IDocList.Objeccts() iterator in a "for" loop, then search manually into each iterated IDocDict for a match.
Offline
I want to do something like below. I did what I wanted manually with the loop. Thanks.
IDocList.Objects('name LIKE test%')
or
IDocList.Objects('name', '%test%', coLike)
or
IDocList.Objects('name', 'test', coInclude)
or
IDocList.Objects('name', 'test', coStartsWith)
or
IDocList.Objects('name', 'test', coEndsWith)
Last edited by nakisen (2024-05-13 11:42:33)
Offline
Hi
Is this the correct method to delete the object/objects?
for AObj in AList.Objects(LCompareStr) do
AList.Remove(AObj.AsVariant);
Last edited by nakisen (2024-05-14 16:34:07)
Offline
Pages: 1