Help with TMethodCall

Hi,

I have a standalone root gui, and i would like to give the user the possibility to declare new methods (always with the same prototype) in this gui. Is it possible? The goal is to make personnalised filters in my application.

what i want:

Enter your method:

Double_t isXPositive(myClass * m)
{
return (m->getX() > 0)
}
| OK |

Is it possible to execute this with cint insisde compiled code? and then use:
TMethodCall * m = new TMethodCall();
m->isXPositive(name, “myClass*”);
MyTrack * args[1];
args[0] = new myClass();
Double_t temp;
cour->SetParamPtrs(args);
cour->Execute(temp);

Laurent

Hi Laurent,
yes, that’s possible. See CINT’s G__CallFunc (in CallFunc.h). Use cases are e.g. in tree/src/TSelectorCint.cxx - fFuncVersion might give you some hints. Let me know if you need more details!
Axel.

Thanks for your reply

I will try to understand this. :-k

For information, i have used a solution not elegant, but it works.
I have used a tgtextedit, to write a macro containing all filters.
example:

[code]filter()
{
}

Bool_t filter1(myclass * m)
{
return (m->isOk());
}
[/code]

and then I execute this macro with gROOT->LoadMacro();

and to get the list of these filters, i use

TList * lst = (TList *)gROOT->GetListOfGlobalFunctions(kTRUE); TIter myIter(lst); TFunction * cour; while ((cour = (TFunction *)myIter.Next())) { TList * lstArgs = cour->GetListOfMethodArgs(); TMethodArg * arg = (TMethodArg *)lstArgs->First(); if (strcmp(cour->GetReturnTypeName(),"Bool_t")==0 && arg && strcmp(arg->GetFullTypeName(),"myclass*")==0) { cout << cour->GetPrototype() << endl; } }

and then i can use these filters with:

TMethodCall * m = new TMethodCall(); m->InitWithPrototype("filter1","myclass*"); MyTrack * args[1]; args[0] = new myClass(); Double_t temp; cour->SetParamPtrs(args); cour->Execute(temp);