Calling a function inside a panel at run time (OOP/Property Related)?

Discussion about recent product features & solutions!
2 posts • Page 1 of 1
leonmf
Posts:6
Joined: Mon Aug 11, 2014 6:21 pm

Calling a function inside a panel at run time (OOP/Property Related)?

Post by leonmf »

I don't post here much because I usually consider my questions too stupid to bother a forum with... :)

I'm in the middle of a reasonably significant size project and our team has heavily utilized the new OOP design patterns with classes for each object with minimum code int the panels, properties instead of $params, etc. This works really well, except when I want to do bulk operations or use addSymbol on one of my objects.

Let's say my object has a caption property.

--------------------------------------
//Button Caption
#property string caption

public void setCaption(string newCaption)
{
ButtonObject.text = newCaption;
}

public string getCaption()
{
return ButtonObject.text;
}
--------------------------------------

Now, if I drop an instance of my button on the parent panel and name it BO1, I can change the caption programmatically by using:

BO1.setCaption(myNewCaption);

This works fine if I only have a couple of objects on my screen.

If I have a bunch of buttons or want to use addSymbol, I can no longer just directly reference the subroutines because I cannot access user created properties or functions at run time.

Neither of these works:
setValue("BO1","caption",newCaption);
callFunction("BO1.setCaption", newCaption);

I saw reference to function pointers only working on static functions (which may be related to what's going on here?) but I can't create a static function in a panel.

Is this just something I have to work around by returning to $ parameters in my object instantiation or am I missing something?

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: Calling a function inside a panel at run time (OOP/Property Related)?

Post by mkoller »

There are several possibilities to use user created properties or functions at run time when you like to address the object via string:

- invokeMethod("BO1", "setCaption", newCaption)
- shape s = getShape("BO1"); s.setCaption(newCaption);

2 posts • Page 1 of 1