OriginObject::DoMethod

 

Description

Execute object LabTalk methods

Syntax

int DoMethod( LPCSTR lpcszCmd, DWORD dwCntrl = 0, double * pdVal = NULL )
int DoMethod( LPCSTR lpcszCmd, LPCSTR lpcszArg, double * pdVal = NULL);
int DoMethod( LPCSTR lpcszCmd, LPCSTR lpcszArg, string & strReturn);

Parameters

lpcszCmd
[input] Object method name, case insensitive
dwCntrl
[input] method's input if require
pdVal
[output] return value, if index variable type, 1 offset, like Labtalk
lpcszCmd
[input] Object method name, case insensitive
lpcszArg
[input] method's input if require
strReturn
[output] return value, if index variable type, 1 offset, like Labtalk
lpcszCmd
[input] Object method name, case insensitive
lpcszArg
[input] method's input if require
pdVal
[output] return string value

Return

Returns 1 if lpcszCmd is a valid method and 0 if it is not. -1 if error occurs If pdVal is NULL will return the method return integer value directly

Examples

EX1

void DoMethod_ex1(string strSheetName)
{
        Page pg = Project.Pages();
        double dRet;
        int nRet = pg.DoMethod("layerNumber", strSheetName, &dRet);
        int nRet2 = pg.DoMethod("layerNumber", strSheetName);
}

EX2

void DoMethod_ex2()
{
        Worksheet wks = Project.ActiveLayer();
        int nn = wks.DoMethod("dc.Allow", 1);
        out_int("wks.dc.Allow(1) = ", nn);
}

EX3

void cpdc()
{
        WorksheetPage wp = Project.Pages();
        wp.DoMethod("cp.add", "1 40 DataConnector 3");// show Control Pane
        GETN_BOX(trTemp)
        GETN_NUM(xFrom, "X From", 1.3)
        GETN_NUM(xStep, "X Step", -0.5)
        string strxml = trTemp.XML;
        wp.DoMethod("cp.SetTree", strxml);
}

EX4

//DoMethod is implemented for Column class in 9.8b
void DoMethod_col()
{
        Worksheet wks = Project.ActiveLayer();
        Column cc(wks, 1);
        LT_set_str("%Z", "A+1");
        cc.DoMethod("SetFormula", "Z, 1");
}

EX5

//add "NextName" to get next object name in v2022:
void abb(string str1="abc")
{
        Layer ly = Project.ActiveLayer();
        string strNew;
        ly.DoMethod("NextName", str1, strNew);
        out_str(strNew);

EX6

void        test_DoMethod_String()
{
        string strReturn;
        Worksheet wks = Project.ActiveLayer();
        int        nRet = wks.DoMethod("Cell", "2, 2", strReturn);
        out_str(strReturn);
}

EX7

OC codes to set/get cell note
//Get/Set cell comments
void DoMethod_SetNode_GetNode()
{
        Worksheet wks = Project.ActiveLayer();
        
        //set comments to cell(4,2)
        string strSNote = "some junk";
        wks.DoMethod("SetNote", "4,2", strSNote);//row=4, col=2. Column can be name or index
        
        //get comments
        string strGNote;
        wks.DoMethod("GetNote", "4,B", strGNote);//row=4, col=B
        out_str(strGNote);
}


EX8

OC codes to add button to worksheet
void wbb(string strLT="ty -b hello")
{
        string strName = "Junk";
        string strLabel = "Click Me";
        
        Worksheet wks = Project.ActiveLayer();
        GraphObject     btn = wks.GraphObjects(strName);
        if(btn)
        {
                out_str("already created");
                return;
        }

        //add gap on the top of the worksheet
        wks.SetProp("Gap", 38);

        //add button
        string strArg = strName;
        strArg += " ";
        strArg += strLabel;
        if(wks.DoMethod("AddButton", strArg) != 0)
        {
                out_str("some err");
                return;
        }
        btn = wks.GraphObjects(strName);
        btn.SetProp("Script", strLT);
}

Remark

See Also

OriginObject::SetProp
LT_evaluate
Layer::LT_execute

Header to Included

origin.h