Board index » delphi » Help - EVariantError

Help - EVariantError

Hi,

I've a function:-

function TDEBSData.EBstableRead
              (DataSet: TDataSet; const KeyValues: Variant): Boolean;
begin
   ..
        (DataSet as TTable).FindNearest([KeyValues]);
  ..
end;{'EBstableRead'}

Each record consists of a TDateField and a TSmallintField; both fields are
the key.

Can anyone tell me why this call to the function works:-

          if EBstableRead(NonBankDTable, (StartDate+i)) then

but this call:-

          if EBstableRead(NonBankDTable,
                                          VarArrayOf([(StartDate+i), 0]))
then

blows out at 'FindNearest' with an EVariantError 'Invalid variant type
conversion'?

It's definitely the 'FindNearest' line that's blowing out (confirmed by
stepping thru' the code in the De{*word*81}).

It's definitely the date that's causing the problem, confirmed by removing
the ', 0' from the VarArrayOf. For what it's worth, the EVariantError
message is followed immediately by EDatabaseError 'Invalid value for field
'Date''.

The date is '36119' ('20th November 1998' to you and me) and was used in
both function calls.

Any assistance gratefully received - e-mail appreciated (my Reply-To Address
is (should be?) anti-spammed, but should be decipherable).

Regards,

Stuart

 

Re:Help - EVariantError


Quote
Stuart wrote:
> It's definitely the date that's causing the problem, confirmed by removing
> the ', 0' from the VarArrayOf. For what it's worth, the EVariantError
> message is followed immediately by EDatabaseError 'Invalid value for field
> 'Date''.

Sounds really funky, Stuart, but I've run into this "invalid variant
type conversion" message from time to time and *eaten it* with a
Try..Finally block with no ill effect!
(burp)

Other Threads