Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Use return value 'object' from TFlexCelUserFunctio

 Post Reply Post Reply
Author
Bernd Kicker View Drop Down
New Member
New Member
Avatar

Joined: 12 Apr 2019
Posts: 1
Post Options Post Options   Quote Bernd Kicker Quote  Post ReplyReply Direct Link To This Post Topic: Use return value 'object' from TFlexCelUserFunctio
    Posted: 14 Aug 2019 at 1:36pm
I wrote a simple user function to retrieve a single value from a list of objects:

class AccessorFunction : TFlexCelUserFunction
{
public override object Evaluate(object[] parameters)
{
var list = parameters.ElementAt(0) as IList;
var index = Convert.ToInt32(parameters.ElementAt(1));
return list[index];
}
}

Everything works fine, except that I have no idea how to use the return value of the function in my report as it is not a primitive datatype but an object.

I imagine something like that:

<#Accessor(<#Objects>;0)>.PropertyName

Is the usage of a user function like that supported by flexcel or is it expected to always return a primitive datatype?
Back to Top
Adrian Gallero View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 1212
Post Options Post Options   Quote Adrian Gallero Quote  Post ReplyReply Direct Link To This Post Posted: Yesterday at 1:06pm
Hi
Sadly the objects that you can access with a syntax like <#Accessor(<#Objects>;0)>.PropertyName
 must be objects FlexCel knows about at compile time, since the template is precompiled before running, and we can't know if an arbitrary object like the result from an user defined function has a property named "PropertyName" or not. (we raise an error if the property doesn't exist at this precompiling phase, and that is very useful since you could have mistyped PropertyName).

What maybe could be done, even if not elegant, is to define the UDF with 3 parameters like:

<#Accessor(<#Objects>;PropertyName;0)>

Then in the evaluate function, you can use Reflection to return the primitive value of Objects.PropertyName. With a little more of fiddling, you could also separate the PropertyName with dots in the Evaluate functions, so you could write:
<#Accessor(<#Objects>;PropertyName.SubProperty2.Prop3;0)>
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down