Board index » delphi » How to use Table.Locate method for more than one fields search

How to use Table.Locate method for more than one fields search

'KeyValues is a variant specifying the field value to match, or an array of field values, if
KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

I want to search two fields values and I have tried that

Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

where FieldValue1, FieldValue2 are two string value.

After compile, I got error messages as follow:

Error: Ordinal type required.
Error: Incompatible types: 'Integer' and 'string'.

I also tried that

Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

After compile, I got error messages as follow:

Error: Incompatible types: 'Variant' and 'Array'.

What is the exact syntex of the 'locate' method for searching more than one fields.

Please, help!

---Jinglan Wang

 

Re:How to use Table.Locate method for more than one fields search


'KeyValues is a variant specifying the field value to match, or an array of field values, if
KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

I want to search two fields values and I have tried that

Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

where FieldValue1, FieldValue2 are two string value.

After compile, I got error messages as follow:

Error: Ordinal type required.
Error: Incompatible types: 'Integer' and 'string'.

I also tried that

Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

After compile, I got error messages as follow:

Error: Incompatible types: 'Variant' and 'Array'.

What is the exact syntex of the 'locate' method for searching more than one fields.

Please, help!

---Jinglan Wang

Re:How to use Table.Locate method for more than one fields search


'KeyValues is a variant specifying the field value to match, or an array of field values, if
KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

I want to search two fields values and I have tried that

Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

where FieldValue1, FieldValue2 are two string value.

After compile, I got error messages as follow:

Error: Ordinal type required.
Error: Incompatible types: 'Integer' and 'string'.

I also tried that

Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

After compile, I got error messages as follow:

Error: Incompatible types: 'Variant' and 'Array'.

What is the exact syntex of the 'locate' method for searching more than one fields.

Please, help!

---Jinglan Wang

Re:How to use Table.Locate method for more than one fields search


Quote
jinglan wang wrote:

> 'KeyValues is a variant specifying the field value to match, or an array of field values, if
> KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

> I want to search two fields values and I have tried that

> Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

> where FieldValue1, FieldValue2 are two string value.

> After compile, I got error messages as follow:

> Error: Ordinal type required.
> Error: Incompatible types: 'Integer' and 'string'.

> I also tried that

> Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

> where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

> After compile, I got error messages as follow:

> Error: Incompatible types: 'Variant' and 'Array'.

> What is the exact syntex of the 'locate' method for searching more than one fields.

> Please, help!

> ---Jinglan Wang

Let me try this from memory,

  I did this at work, and my Delphi at home does not have the Help updated.  But I had to create a variant
array, stuff the values in the array and use that as the second argument.
  LocateArray: Variant;

  with Table do
  LocateArray := VariantArrayCreate( [0,1], xxx ) { <-- the second parameter uses enumerated constants to
identify the type of array.  You will have to find the documentation on the VariantArrayCreate function.}

  LocateArray[0] := FieldbyName( 'Field1Name' ).Value;
  LocateArray[1] := FieldbyName( 'Field2Name' ).Value;

  if  Locate( 'Field1Name;Field2Name', LocateArray, [loPartialKey] ) then
    begin
       {whatever)
    end;

This is kind of fuzzy, so verify my code in the Help.

Jim

Re:How to use Table.Locate method for more than one fields search


'KeyValues is a variant specifying the field value to match, or an array of field values, if
KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

I want to search two fields values and I have tried that

Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

where FieldValue1, FieldValue2 are two string value.

After compile, I got error messages as follow:

Error: Ordinal type required.
Error: Incompatible types: 'Integer' and 'string'.

I also tried that

Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

After compile, I got error messages as follow:

Error: Incompatible types: 'Variant' and 'Array'.

What is the exact syntex of the 'locate' method for searching more than one fields.

Please, help!

---Jinglan Wang

Re:How to use Table.Locate method for more than one fields search


Quote
jinglan wang wrote:

> 'KeyValues is a variant specifying the field value to match, or an array of field values, if
> KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

> I want to search two fields values and I have tried that

> Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

> where FieldValue1, FieldValue2 are two string value.

> After compile, I got error messages as follow:

> Error: Ordinal type required.
> Error: Incompatible types: 'Integer' and 'string'.

> I also tried that

> Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

> where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

> After compile, I got error messages as follow:

> Error: Incompatible types: 'Variant' and 'Array'.

> What is the exact syntex of the 'locate' method for searching more than one fields.

> Please, help!

> ---Jinglan Wang

You can use the VarArrayOf function to construct a variant array on the
fly. The locate would look like:

  Table.Locate('FieldName1;FieldName2', VarArrayOf([FieldValue1,
FieldValue2]), [loPartialKey]);

--
Try walking in my shoes - You'll stumble in my footsteps (Depeche Mode)
WWW:   http://www.{*word*104}enet.net/~peterp/
email: pet...@{*word*104}enet.net

Re:How to use Table.Locate method for more than one fields search


Quote
Jim Poe <Jim...@gnn.com> wrote:
>jinglan wang wrote:

>> 'KeyValues is a variant specifying the field value to match, or an array of field values, if
>> KeyFields lists more than one field.' This is in the Delphi Library Reference Help.

>> I want to search two fields values and I have tried that

>> Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2], [loPartialKey]);

>> where FieldValue1, FieldValue2 are two string value.

>> After compile, I got error messages as follow:

>> Error: Ordinal type required.
>> Error: Incompatible types: 'Integer' and 'string'.

>> I also tried that

>> Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

>> where vArray : array[1..2] of string; vArray[1]:=FieldValue1, vArray[2]:=FieldValue2

>> After compile, I got error messages as follow:

>> Error: Incompatible types: 'Variant' and 'Array'.

>> What is the exact syntex of the 'locate' method for searching more than one fields.

>> Please, help!

>> ---Jinglan Wang
>Let me try this from memory,

>  I did this at work, and my Delphi at home does not have the Help updated.  But I had to create a variant
>array, stuff the values in the array and use that as the second argument.
>  LocateArray: Variant;
>  with Table do
>  LocateArray := VariantArrayCreate( [0,1], xxx ) { <-- the second parameter uses enumerated constants to
>identify the type of array.  You will have to find the documentation on the VariantArrayCreate function.}
>  LocateArray[0] := FieldbyName( 'Field1Name' ).Value;
>  LocateArray[1] := FieldbyName( 'Field2Name' ).Value;

>  if  Locate( 'Field1Name;Field2Name', LocateArray, [loPartialKey] ) then
>    begin
>       {whatever)
>    end;

You know, although this sounds about right, doesn't it seem to be just a little
complicated for the results?  What is wrong with the 'Range' methods?  This is a
general question, not pointed at this particular instance....it just seems that
the Locate and Find methods (that use Variants) seem to take more lines of code
to get the same thing done.  Has anyone actually measured this in terms of code
size and speed?

- Show quoted text -

Quote
>This is kind of fuzzy, so verify my code in the Help.
>Jim

Re:How to use Table.Locate method for more than one fields search


jinglan wang <g...@gis.nmt.edu> wrote in article
<31F54B08.5...@gis.nmt.edu>...

Quote
> 'KeyValues is a variant specifying the field value to match, or an array

of field values, if
Quote
> KeyFields lists more than one field.' This is in the Delphi Library
Reference Help.

> I want to search two fields values and I have tried that

> Table.Locate('FieldName1;FieldName2', [FieldValue1, FieldValue2],
[loPartialKey]);

> where FieldValue1, FieldValue2 are two string value.

> After compile, I got error messages as follow:

> Error: Ordinal type required.
> Error: Incompatible types: 'Integer' and 'string'.

> I also tried that

> Table.Locate('FieldName1;FieldName2', vArray, [loPartialKey]);

> where vArray : array[1..2] of string; vArray[1]:=FieldValue1,

vArray[2]:=FieldValue2

Quote

> After compile, I got error messages as follow:

> Error: Incompatible types: 'Variant' and 'Array'.

> What is the exact syntex of the 'locate' method for searching more than
one fields.

> Please, help!

> ---Jinglan Wang

there are examples of using this key function in my Delphi 2.0 printed
manuals (a pain, I know). try looking in there.

country dave matthews
d...@msn.com
WWW Consultant/Developer--InfoCreations, Co.
www.infocreations.com (under construction)

Other Threads