Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass param by reference or private variable?
Message
 
 
To
03/10/2019 02:09:29
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01671293
Message ID:
01671361
Views:
47
>>>>>>Hi,
>>>>>>
>>>>>>I need a method of a object to return some strings (actually two). I can declare the variables as Private before calling the method and set the values of the variables inside the method.
>>>>>>Or I can declare the variables Local and pass them by reference (with @). Therefore, when passing by reference the variable value can be set within the method and afterward get the value.
>>>>>>What is better practice?
>>>>>
>>>>>Return an object based on empty with properties storing return values. This way you can return as many strings or not strings as you want
>>>>
>>>>I just did a little test. And it appears that creating an empty object is fairly simple
>>>>
>>>>oEmpty = CREATEOBJECT("empty")
>>>>ADDPROPERTY( oEmpty, "return_success",.T.)
>>>>ADDPROPERTY( oEmpty, "string1","abc")
>>>>ADDPROPERTY( oEmpty, "string2","123")
>>>>oEmpty.return_success = .F.
>>>>RETURN 
>>>>
>>>>
>>>>Thank you.
>>>
>>>I strongly suggest you to use "_.prg" ( https://github.com/nftools/underscore )
>>>
>>>With it you can get rid of addproperty, and instead just do:
>>>
>>>
>>>
>>>set path to "..\underscore" addititive
>>>
>>>oEmpty = CREATEOBJECT("empty")
>>>
>>>with _( m.oEmpty )
>>>   .return_success = .T.
>>>   .string1 = "abc"
>>>   .string2 = 123
>>>endwith
>>>
>>>
>>
>>Thank you for your input. But why "strongly"? And what is the benefit of getting rid of addproperty?
>
>Actually you don't get rid of AddProperty, you just don't have to type it since the program does it for you. So he only benefit is a little less typing.

Thank you, Tore. Does not sound to me like so much of a benefit.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform