— No Results

    Add methods

    Define method in Script Engine

    scriptEngine->AddMethod ("function ValueInRange(Value: Variant, Min: Extended, Max: Extended): Boolean", CustomScriptFunc);
    

    Implement function

    Variant __fastcall TfrmMontageauftrag::CustomScriptFunc (TObject *Object, TMetaClass *MetaClass, UnicodeString FuncName, Variant &Params)
    {
    	if (FuncName == "VALUEINRANGE")
    	{
    		try
    		{
    			float v = StrToFloat (Params.GetElement(0));
    			if (v >= Params.GetElement(1) && v <= Params.GetElement(2)) return true;
    		}
    
    		catch (...)
    		{
    		}
    
    		return false;
    	}
    
    	return NULL;
    }
    

    Variable passing by reference

    void __fastcall TfrmMontageauftrag::ComponentEventOnValidate (System::TObject* Sender, System::Variant &DisplayValue, Vcl::Controls::TCaption &ErrorText, bool &Error)
    {
    	int bounds[2] = {0, 3};
    	Variant Result = VarArrayCreate (bounds, 1, varVariant);
    
    	Result.PutElement (Sender, 0);
    	Result.PutElement (DisplayValue, 1);
    	Result.PutElement (ErrorText, 2);
    	Result.PutElement (Error, 3);
    
    	sc->CallFunction1 /*use CallFunction1 when using parameters passed by reference*/ (events->OnValidate, Result, false);
    
    	DisplayValue = Result.GetElement (1);
    	ErrorText = Result.GetElement (2);
    	Error = Result.GetElement(3);
    
    	VarClear (Result);
    }
    

    cppbuilder/snippets/fastscript/addmethod.txt · Last modified: 2019/07/01 09:45 by administrator