O$6.0.3 – Calling a method using a private method as a parameter
Hi Alex,
Thanks. I tried callprivate() last night with no luck but I must have had the syntax wrong somewhere. I’ll give it another go đ
Lawrence
Sent from my iPhone
> On Jun 3, 2017, at 3:07 PM, Alex Clay <aclay@mac.com> wrote:
>
> Hi Lawrence,
>
> Try using the callprivate() function. Per the Omnis docs:
>
>> Syntax
>> callprivate(method[,parameters…])
>>
>> Description
>> Calls the private method with the specified parameters and returns its return value
>
> Here’s the example I put together. Given the method someMethod:
>
>> pnValue1: Number floating dp
>> pnValue2: Number floating dp
>>
>> Quit method pnValue1+pnValue2
>
> And the method callMe:
>
>>
>> pnValue: Number floating dp
>>
>> Quit method con(“I received “,pnValue)
>
> This code:
>
>> Do method callMe (callprivate(“someMethod”,1.11,2.22)) Returns lcResult
>
> Will produce “I received 3.33” as lcResult.
>
> If you want to ensure the private method exists you can use $methods.$findname() per your example:
>
>> Do method callMe (callprivate($cinst.$methods.$findname(“someMethod”).$name,1.11,2.22)) Returns lcResult
>
>
> However, callprivate() will throw an error if the passed method name is invalid, so you might not need the extra validation.
>
> Alex
>
>> On Jun 3, 2017, at 08:26, lawrence@lawrencesmith.com wrote:
>>
>> no joy.
>>
>>
>> Do method callMe($cclass.$methods.$findname(âsomeMethodâ).$name()) just passes the name âsomeMethod’ to callMe. What i want is for someMethod to execute âin lineâ and pass it’s return value to callMe.
>>
>>
>>
>> Lawrence
>>
>>
>>> On Jun 3, 2017, at 8:09 AM, lawrence@lawrencesmith.com wrote:
>>>
>>> Vik,
>>>
>>>
>>> Thanks for the reply.
>>>
>>> Yesterday I tried using
>>>
>>> do method callMe($cinst,$methods.someMethod)
>>>
>>> but that doesnât work. iâll try using .$findname and see if that does the trick. Ugly syntax and once again requires embedding a literal string in the code (something I avoid like the plague).
>>>
>>> On a different note I like $cando()
>>>
>>> Best,
>>>
>>> Lawrence
>>>
>>>> On Jun 3, 2017, at 4:54 AM, Vik Shah <Vik@Keys2Solutions.com.au> wrote:
>>>>
>>>> Hi Lawrence,
>>>>
>>>> I think what you are after is $cmethod.$name or is it $cmethod().$name. This will eliminate any unknown values being passed around.
>>>> NOTE: passing in $cmethod as a parameter will pass a link to the current executing method before it jumped into the new method.
>>>>
>>>> So from the calling method you ca do, the followingâŠ
>>>> 1. Do method callMe($cmethod().$name)
>>>> 2. Do method callMe($cclass.$methods.$findname(âsomeMethodâ).$name())
>>>>
>>>> Another thing you can add to your âcallMeâ method is a test to see if the name exists⊠There are again a few ways of doing it…
>>>> 1. if not(isclear($cclass.$methods.$findname(âsomeMethodâ)))…
>>>> 2. if not($cclass.$methods.[method_name_var].$ident.$cando())
>>>>
>>>> The $cando() technique is a boolean test to see if a specific notation query can be executed.
>>>>
>>>> HTH
>>>>
>>>> Regards,
>>>>
>>>> Vik Shah
>>>> Director
>>>> Keys2Solutions
>>>> AU: +61 411 493 495
>>>> US: +1 (415) 413 4172
>>>> US: +1 (646) 583 2403
>>>>
>>>>
>>>>> On 3 Jun 2017, at 05:07, lawrence@lawrencesmith.com wrote:
>>>>>
>>>>> All,
>>>>>
>>>>> Assuming a single class, I want to a call a method and use an inline call to a private method as a parameter value. I can successfully use a public method as the parameter (e.g. do method callMe($cinst.$someMethod)) but I donât really want to make $someMethod part of the public API. I want to make the call the equivalent of: do method callMe(do method someMethod). I realize I could pass the private method name as text and then perform a do method [passedValue] inside the receiving method but the calling syntax is less expressive that way, more prone to typos, and doesnât pass my personal âthis is clearly a hackâ test. There are certainly times when passing the method name as text is an appropriate solution (delayed execution etc) but in this case not so much.
>>>>>
>>>>> Any thoughts?
>>>>>
>>>>> Lawrence
>>>>> _____________________________________________________________
>>>>> Manage your list subscriptions at lists.omnis-dev.com
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _____________________________________________________________
>>>> Manage your list subscriptions at lists.omnis-dev.com
>>>
>>>
>>> _____________________________________________________________
>>> Manage your list subscriptions at lists.omnis-dev.com
>>
>>
>> _____________________________________________________________
>> Manage your list subscriptions at lists.omnis-dev.com
>
>
> _____________________________________________________________
> Manage your list subscriptions at lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com