UCMDs: using fields in a cmd-class

SALT, SPICE, Subversion, etc...
Post Reply
User avatar
MBaas
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany
Contact:

UCMDs: using fields in a cmd-class

Post 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?
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: UCMDs: using fields in a cmd-class

Post 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.
User avatar
MBaas
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany
Contact:

Re: UCMDs: using fields in a cmd-class

Post by MBaas »

Thanks, that's it! :-)
DanB|Dyalog

Re: UCMDs: using fields in a cmd-class

Post 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.
Post Reply