UCMDs: using fields in a cmd-class

SALT, SPICE, Subversion, etc...

UCMDs: using fields in a cmd-class

Postby MBaas on Sat Feb 11, 2012 7:57 am

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

Re: UCMDs: using fields in a cmd-class

Postby Phil Last on Sat Feb 11, 2012 8:54 am

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
Phil Last
 
Posts: 441
Joined: Thu Jun 18, 2009 6:29 pm

Re: UCMDs: using fields in a cmd-class

Postby MBaas on Sat Feb 11, 2012 9:08 am

Thanks, that's it! :-)
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: UCMDs: using fields in a cmd-class

Postby DanB|Dyalog on Sat Feb 11, 2012 8:10 pm

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.
DanB|Dyalog
 


Return to Source Code Management

Who is online

Users browsing this forum: No registered users and 1 guest