Title: Returning an Interface from a Function Post by: Trent H. on October 09, 2023, 12:02:36 pm I'm busy looking into implementing the new Genero Methods into an application and was wondering how to return an Interface from a Function
I have two example Types set up as Code
And Code
Then an Interface to use them with as Code
It seems to work fine but how can they be used in a scenario like the below where I need to return an Interface depending on an argument Code
I'm trying to use in the code in MAIN as Code
Title: Re: Returning an Interface from a Function Post by: Leo S. on October 09, 2023, 03:10:05 pm Hi Trent, you need to make use of the optional RETURNS clause of the FUNCTION typeBuilder
Also , since 4.1.x you don't need to return record.* anymore. Just do this Code Regards , Leo Title: Re: Returning an Interface from a Function Post by: Trent H. on October 09, 2023, 04:08:29 pm Hello Leo, thanks so much for the response.
I've updated the code and it is compiling fine which is great but I am getting a "Null pointer exception" on the CALL itype.test() line in the polyTest FUNCTION. Do I need to make any other changes for it to work with Genero 3.20? (I should have mentioned I'm not using 4.10 yet) Title: Re: Returning an Interface from a Function Post by: Leo S. on October 09, 2023, 05:24:30 pm Hi Trent , I needed to fiddle a bit to make it working in 3.20,
the following code should compile and run at your side, see the comments which explain a bit the difference to 4.x Of course this code works also once you switch to 4.x Code Regards, Leo Title: Re: Returning an Interface from a Function Post by: Leo S. on October 09, 2023, 05:55:10 pm Trent, I double checked against 4.x: also in 4.x you can't return an interface variable (which is a kinda pointer) from a variable which has function local scope.
The runtime does set it to NULL on return because the local scope of the typeBuilder was left ...and there is no mechanism in Genero which allows to point to scopes which have been destroyed. (It would be possible in theory by creating a temp variable and using a garbage collector). So just use variables which have module scope for the builder and you are fine. Regards, Leo Title: Re: Returning an Interface from a Function Post by: Trent H. on October 09, 2023, 09:29:23 pm Hello Leo, oh ok I see, a bit unexpected but I think I can work with this. Thanks so much for your help! I would never have figured that out, haha
|