Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
X# examples - Finger prints
Message
From
01/11/2019 06:51:53
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
To
31/10/2019 04:16:46
General information
Forum:
Visual FoxPro
Category:
VFP Compiler for .NET
Miscellaneous
Thread ID:
01671748
Message ID:
01671772
Views:
59
>Hi all,
>
>One of the nice features of .NET which I think is not always utilized to the max, is when an "unknown" parent needs to be accessed. Consider an object that needs to look for a value of the parent class, however the parent type is unknown hence if we on an orderline we might want to determine the OrderNo of the order this orderline is associated with. We would therefore have an oParent.OrderNo. Problem is in strict type code it is sometimes difficult to pass in oOrder. The OrderNo might actually belong to the OrderNo of the Customer object. Delegates to the rescue.
>
>
>DELEGATE OrderNum() AS INT
>
>CLASS OrderLine
>  PROTECT OrderNo AS OrderNum
>  CONSTRUCTOR(OrdNum AS OrderNum)
>    THIS.OrderNo = OrdNum
>  RETURN
>  PROPERTY OrderNum AS INT
>    GET
>      RETURN THIS.OrderNo()
>    END GET
>  END PROPERTY
>END CLASS
>
>CLASS SomeParentClass
>  PUBLIC OrderNum AS INT
>  METHOD GetMyOrderNum() AS INT
>  RETURN THIS.OrderNum
>END CLASS
>
>
>Then in our code:
>
>
>LOCAL oParent = SomeParentClass()
>LOCAL ordNumbr = oParent.GetMyOrderNum AS OrderNum
>oOrderItem = OrderLine(ordNumbr)
>? oOrderItem.OrderNum && This actually returns oParent.GetMyOrderNum
>
>
>We can also use this to do the following:
>
>
>DELEGATE SayHello() AS STRING
>
>FUNCTION French() AS STRING
>RETURN "Bon jour"
>
>FUNCTION English() AS STRING
>RETURN "Good morning"
>
>FUNCTION Start() AS VOID
>  LOCAL Hello as SayHello
>  Hello = English
>  ? Hello() && "Good morning"
>  Hello = French
>  ? Hello() && "Bon jour"
>RETURN
>
Talking about readability, this is very confusing.
LOCAL Hello as SayHello
What, a variable is declared as a function? And actually just a declaration, because the function doesn't exist. And it's not even a function class, it's a dummy. Next it doesn't say FUNCTION French() AS SayHello, but "as string". Then
Hello = English
variable is assigned a function (!). What is this, javascript? The point with delegation of this sort is that you can make your code configurable, so if there's a setting that needs different pieces of code to act depending on its values (language is not quite a good example, translations are usually done in a simpler way) - let's say it changes date, time and currency formats... so how do you store those function names in any config file? Or in a table? Can you store the value of such a variable into any file/table/dataset and then later retrieve it into another such variable?

I remember I once had an interest calculation, which would use one of three methods of calculating interest, depending on the contract - so the method name would be in the contracts table. Then when calculating, I'd just compose the function name from contents of that field, and do some kind of macro substitution (or eval() or execscript(), whichever was in the fashion that year) from that.
How would that name translate into one of those function names? Would you have to write a long case statement with
case method="m01"
CalcFn=method01
Keep in mind that in fox I could simply add a method99.prg and store "m99" in the contracts table without even recompiling the project - just existence of method99.fxp somewhere in the app's internal path sufficed.

You can see how this can look confusing for native foxen who don't speak .net - and such things were mostly the reason I still don't speak it :).

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform