class EVariantTypeCastError with message 'Could not convert variant of type (String) into type (Double)

10,722

This is just the debugger. It's probably just getting an expected error (one handled by a try..except in the FR code) and properly dealing with it, but the debugger has no way of knowing that and tells you the exception happened. (It's a common issue when working with Indy, which raises exceptions as part of normal program flow.)

There are three ways to deal with this situation when debugging:

  1. Just hit Continue on the exception dialog when it appears. (You can tell it's a debugger exception because you get the Break or Continue option, and because it only happens when debugging.)

  2. You can disable a specific exception class (or all exceptions) when debugging, using the Tools->Options->Debugger Options. In this case, you can add EVariantTypeCastError to the list of exceptions to ignore.

  3. (My preferred method) Use the Advanced Breakpoint Properties dialog to skip the debugger's exception handling around the specific line of code you know will raise the exception you want to ignore.

    • Set a breakpoint on the line immediately before the problem code line.
    • Right-click the breakpoint on the line before, and choose Breakpoint Properties from the context menu.
    • Click the Advanced button on the Breakpoint Properties dialog, and in the Actions groupbox, uncheck Break and check Ignore subsequent exceptions.
    • Repeat the previous steps on the line after the problem code, except check Break and uncheck Ignore subsequent exceptions on this second breakpoint.
    • Run your code as usual. The debugger will skip it's exception handling on the code between the two breakpoints.

The advantage of option #3 is that it ignores all exception handling, but only on the code block between the two breakpoints, so you still get exceptions in all other areas of your code that may be valid exceptions in the debugger.

Share:
10,722
zac
Author by

zac

I like programming, learning, video games and watching movies.

Updated on June 26, 2022

Comments

  • zac
    zac almost 2 years

    Using Delphi and FastReport I get this error message while debugging inside Delphi immediately after this line:

    <FastReport_Component>.ShowReport(true);
    

    Then this error appear:

    Project myapp.exe raised exception class EVariantTypeCastError with message 'Could not convert variant of type (String) into type (Double)'.

    It appears twice before displaying the report. but if I run myapp without debugging no error message appear.

    How I can find which memo cause this error ? the report has so many memos. some has also expressions inside using IIF and the error message does not display any more info.

  • dummzeuch
    dummzeuch almost 8 years
    Your option 3, while in theory a very nice solution, only works until somebody removes these breakpoints. And this can easily happen with the Delete All Breakpoints menu. I do this regularly since my IDE tends to keep invalids breakpoints around which can't be deleted individually.
  • Ken White
    Ken White almost 8 years
    @dummzeuch: At which point you repeat the simple, 5 step process to put it back where you need it. I didn't say anywhere that it was a permanent way to handle the exception (that would be option 2).