Page 1 of 1

UCMDs: using fields in a cmd-class

Posted: Sat Feb 11, 2012 7:57 am
by MBaas
I tried to define a field in a class which is used to implement a ucmd:
      :Field Public ReadOnly FCHomeDir←'c:\temp\'


I also tried making the field private, but both variants cause the err-msg: "Cannot access instance field from within a class"

What's wrong?

Re: UCMDs: using fields in a cmd-class

Posted: Sat Feb 11, 2012 8:54 am
by Phil Last
I was going to suggest the word "Shared" as opposed to the word "Instance" that's implied by default 'til I remembered that I don't actually do this stuff so I deleted it.

But you could give it a try.

Re: UCMDs: using fields in a cmd-class

Posted: Sat Feb 11, 2012 9:08 am
by MBaas
Thanks, that's it! :-)

Re: UCMDs: using fields in a cmd-class

Posted: Sat Feb 11, 2012 8:10 pm
by DanB|Dyalog
Yes, Phil is right as you found out.
Scripts can contain a class or a namespace.
Since no instance is taken from the class and that the code is hidden, there is no benefit in using a class.
In fact it is rather the opposite: since classes hide everything you are restricted when looking at objects within it.
For example, the command ]display cannot be used to show you the contents of expressions involving fields in your command (or your command has stopped and you wish to see their contents manually). Same with ]umonitor that cannot be used on fns in classes, even if public.
In general I recommend to use namespaces instead of classes.
In 13.1 command ]UNEW has been modified to generate a namespace.