Mega Code Archive

 
Categories / Delphi / Examples
 

Locate[] fails with variant conversion error

Locate() fails with a 'Variant conversion error', if you search for only one field and have this in a variant array. This is a problem if you create the array to search for dynamically at runtime. In the case, that you array would have only one entry, you have to pass the value itself: Note: This was observed under Delphi 3 with BDE 5 using InterBase and MS-SQL. I don't know if the problem occurs with later versions of Delphi. BDE version and dbms should not matter. begin .. MyArr := .. FieldStr := .. case FieldCount of 0: // error 1: found := Table1.Locate(FieldStr, MyArr[0], []); else found := Table1.Locate(FieldStr, MyArr, []); end; end.