Invalid variant type conversion...

I'm having trouble with variables on FastReport...

I added the function AnsiReplaceStr to my FastReport, using the AddFunction method and the OnUserFunction event... It appears to be added correctly, but when I tried to call the function, I get the error "Invalid variant type conversion"...

This error appears for me everytime I try to use a variable on FastReport...

I created a variable on Fast and I tried to use it that way:
procedure MemoCliOnBeforePrint(Sender: TfrxComponent);
Var wI : Integer;
begin
    MemoCli.Memo.Clear;
    MemoCli.Memo.Add( 'A' );
    For wI := 1 To StrToInt( Copy( VarToStr( <wCliSpaces> ), 1, 2 ) ) Do
        MemoCli.Memo.Add( ' ' );
End;

But the error appears here too...

Finally, how to use variables on FastReport? Where is my error?

Best regards.

Comments

  • edited 1:39AM
    What Delphi version do you use?
  • edited March 2005
    Delphi 6...
  • edited 1:39AM
    D6 MUST have upd1 and upd2 installed.
  • edited 1:39AM
    Ok... I'll install it... Thank you very much!

    Regards,
    Gabriel Frones
  • edited 1:39AM
    Alex, I installed Delphi update pack 1 and 2, but it still don't works...

    A fragment of my code should help?

    regards.
  • edited 1:39AM
    More details: I could add and use the function AnsiReplaceStr, but on the code I wrote, the error still happening...

    I make some tests, and the error appears to happens only with variables sent by Delphi or already existing on the Report.Variables... There are any diferences on the Reading of procedure's variables and the report's variables?

    regards.
  • edited 1:39AM
    One more thing:
    Var wI : Integer;
        wAux : String;
    begin
        wAux := <wCliSpaces>;
        While Length( wAux ) < 12 Do
            wAux := '0' + wAux;
        MemoCli.Memo.Clear;
        MemoCli.Memo.Add( 'A' );
        For wI := 1 To StrToInt( Copy( wAux, 1, 2 ) )  Do
            MemoCli.Memo.Add( ' ' );
    

    It shows the error "Invalid variant type conversion", but if I remove the two last lines, there are no errors... Why is FastReport Trying to convert Variant, if everything is already on the necessary types?

    regards.
  • edited 1:39AM
    Making some tests and looking for COPY function on FastScript source, I think I found a bug...

    Try to convert the string '0012' to variant and back to string... It will return '12'... Using the Copy function on FastScript (that converts to Variant), if you do a Copy( var, 1, 2 ), the expected result is '00', but it will return '12', theorically... I couldn't make it works, yet...

    regards.
  • edited 1:39AM
    I solved that problem... I wrote the code on Delphi...

    Now I wonder.... For what does FastReports have a Script if it's VERY hard to use a variable?

    regards.
  • edited 1:39AM
    I haven't tried working with FastScript much but I have had challenges when I have worked with it. Mostly my problems revolve around variant type conversions like you're finding.

    If FastScript wasn't a product they sold then I'd suggest using PascalScript which is much closer to Delphi than FastScript is. ;)
  • edited 1:39AM
    By the way, where can I find this PascalScript you talked?

    regards.
  • edited 1:39AM
    As I said before Delphi6 must have two updates installed, in other case you'll get Invalid Variant Conversion errors when running some scripts. To check if updates was installed correctly, run Delphi and make File|New application and compile it. Size of the exe file should be 384000 bytes. If it is not, you haven't installed the updates correctly.
  • edited 1:39AM
    GRFrones wrote:
    Making some tests and looking for COPY function on FastScript source, I think I found a bug...

    Try to convert the string '0012' to variant and back to string... It will return '12'... Using the Copy function on FastScript (that converts to Variant), if you do a Copy( var, 1, 2 ), the expected result is '00', but it will return '12', theorically... I couldn't make it works, yet...

    regards.
    The script
    var
      s: String;
      v: Variant;
    begin
      s := '0012';
      v := s;
      s := v;
      ShowMessage(Copy(s, 1, 2));
    end.
    

    works well for me - prints 00.
  • edited 1:39AM
    I followed the steps, but the size is incorrectly... Clicking in my Help >> About, it shows Version 6.0 (Build 6.240) Update Pack 2...

    If there's something wrong, how can I correct? Can I uninstall and reinstall the Update packs?

    Thank you very much, Alex!

    regards.
  • edited 1:39AM
    Probably you did not install upd1. The best way is to uninstall Delphi and install it again, then install upd1, then upd2.
  • edited April 2005
    Hi... Here I am again... I recently installed the RTL update 3, and the size of the executable was exactly 384Kb (393,216 bytes)... Is it really wrong?

    Thank you very much!

    regars.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.