I am struggling with TCriteria and appreciate every support! Thanks.
This Code spilts a word in pieces and creates a search in BEZEICHNUNG and SYNONYM. If the piece is shorter than 3 Chars, the search is in LEBENSMITTELCD.
However, if there is only one word and Shorter then 3 Chars, the second condition is never met and ExpressionA and ExpressionB are undefined.
bFirstGroup := true;
for s in sSearch.Split([' ']) do begin
if s.Length <= 2 then begin
if bFirstGroup then begin
ExpressionGroup := Linq.like('LebensmittelCD', s + '%');
bFirstGroup := false;
end else begin
ExpressionGroup := ExpressionGroup or Linq.like('LebensmittelCD', s + '%');
end;
end;
end;
bFirst := true;
for s in sSearch.Split([' ']) do begin
if s.Length > 2 then begin
if bFirst then begin
ExpressionA := Linq.like('Bezeichnung', '%' + s + '%');
ExpressionB := Linq.like('Synonym', '%' + s + '%');
bFirst := false;
end else begin
ExpressionA := ExpressionA and Linq.like('Bezeichnung', '%' + s + '%');
ExpressionB := ExpressionB and Linq.like('Synonym', '%' + s + '%');
end;
end;
end;
if bFirstGroup then begin
Criteria.Add(ExpressionA or ExpressionB);
end else begin
Criteria.Add(ExpressionGroup and (ExpressionA or ExpressionB)); < ---- works, although A and B are undefined
end;
DataBLS := Criteria.List; < ------------------- Exception is raised
Is there any way to check, if a TLinqExpression holds an expression? Introducing a flag for every Expression to trace if it?s initialized seems not very elegant.
What do you recommend?