Calling Fun With Parameters from Script

edited 2:33AM in FastScript
Hi

I am new to this fastscript. I have a following script

{
//calling the C++ method without parameters
CPPFunc();

}

In this script there is function/method for which defination is there
in the main form like this -

void TForm1 :: CPPFunc(AnsiString s,int nInteger)
{

//ShowMessage(nInteger);
ShowMessage(s + ', ' + IntToStr(nInteger));
}

The function takes 2 parameters.

I am not able to call this method with parameters from script i.e

{
//calling the C++ method "with parameters"

CPPFunc("Hi Welcome to C++ Script", 2005);

}

If i run this script,its giving error : Too many actual parameters.
If i remove the parameters the script will work but i will not get the parameter values.

Can any one help me?

Thanks
-Veeresh

Comments

  • edited 2:33AM
    Veeresh,
    I'm not really sure exactly what you are trying to do but I'll try to help. I'm new at this too. You must first add a handler method that will be called when your function is encountered in script. Then, when you call AddMethod() you must pass the handler as the second parameter. Try this. If you get comfused e-mail me and I'll send you code.

    //

    //In .h file in the __published: section add thses lines:

    Variant __fastcall VeereshScriptFunctionHandler(TObject *Object, TMetaClass *MetaClass, AnsiString FunctionName, Variant &Params);


    //In the public: section add this:

    void CPPFunc(AnsiString s,int nInteger);



    //

    //in .cpp file add these things:

    //before you call fsScript1->Compile() and fsScript1->Execute()
    //add this line:

    fsScript1->AddMethod("function CPPFUNC (s:String, i:Integer):void",VeereshScriptFunctionHandler,NULL,NULL);


    //Then add your handler function definition:

    Variant __fastcall TForm1::VeereshScriptFunctionHandler(TObject *Object, TMetaClass *MetaClass, AnsiString FunctionName, Variant &Params)
    {
    if(FunctionName== "CPPFUNC")
    {
    AnsiString str=Params.GetElement(0);
    int nInteger=Params.GetElement(1);
    CPPFunc(str,nInteger);
    }


    }
    //
    void TForm1 :: CPPFunc(AnsiString str,int nInteger)
    {
    str+=", "+IntToStr(nInteger);
    ShowMessage(str);
    }
    //



    //Finally, your script will look like this:

    {

    cppfunc("hello world", 9);


    }


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.