Is it Safe to Use the .Tag property ?

Using (or providing) Microsoft.NET Classes

Is it Safe to Use the .Tag property ?

Postby PGilbert on Tue Mar 18, 2014 3:44 pm

The .Tag property is usefull to store some Apl data to be retrieve later. However I stumble on the following:

      ⎕USING←'System.Windows,WPF/PresentationFramework.dll'
win←⎕NEW Window
win
System.Windows.Window

win.Tag←'one' 'two'
win.Tag
one two
⍴win.Tag
2

win.Tag←⊂'one'
win.Tag
one
⍴win.Tag
3


The rank was not preserve in the last example. Is this normal or it should preserve the rank of the APL data ?

Thanks in advance
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Is it Safe to Use the .Tag property ?

Postby Dick Bowman on Tue Mar 18, 2014 5:17 pm

Looks like Microsoft confusing themselves with scalars versus vectors.

Try forcing a vector...

win.Tag←,⊂'one'
⍴win.Tag
1

Seems to do the trick.

Always wise - in my view - when dealing with aliens - to be as consistent as you can be.

Apologies if I'm totally misundertanding.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Is it Safe to Use the .Tag property ?

Postby PGilbert on Tue Mar 18, 2014 9:26 pm

Thanks Dick for your time. I have been always surprised to be able to store all kinds of Apl data in this .Tag and it always worked without knowing how some Apl data could be kept inside a .Net property (.Tag). But now with this example I have become reluctant to do it anymore. My question was more to Dyalog so they could advise if they have a saying in how .Tag behave or not.

In any case I will use something like MyButton.ΔTag←aplData from now on. That way I will be sure not to loose anything and stay on the Apl side. And if you attach an event like onClick to MyButton, the event handler will receive a copy of the sender (MyButton) with the ΔTag that will be accessible to the event handler. Also that way the new Apl property could be name anything that will be more meaningful than .Tag something like ΔState for example.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Is it Safe to Use the .Tag property ?

Postby MikeHughes on Wed Mar 19, 2014 8:03 am

Hi Pierre,

It is perfectly safe to use the Tag property, I use it all the time but not in the way you are using it.
Though I warn you IT IS unsafe to use it in the way you are using it if you use my WPF workspace.

I have two functions Set and Get which manipulate the Tag property of WPF objects which record and retrieve APL data

var1 var2←object Get 'Variable1' 'Variable2'
object Set 'Variable1' var1

I assign to the Tag property the same data structure, namely a vector of nested elements, the default is 1⍴⊂0⍴⊂''
The first element is a list of names, in this case 'Variable1' 'Variable2'
The following elements are the data var1 var2

such that Tag contains a three element vector ('Variable1' 'Variable2') (var1) (var2)

Doing this allows multiple named data items to be held by the Tag property and all of them preserve the APL properties going in and coming out.

However - PLEASE DON'T use the Tag property other than through these functions as a lot of my Event Handling, Data Binding, and other features available through the WPF workspace (to be released with version 14) use Tag in this manner and single, direct data usage is wasteful and conflicts with this usage.

Best regards
Michael
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: Is it Safe to Use the .Tag property ?

Postby PGilbert on Wed Mar 19, 2014 1:49 pm

Thanks Michael for your detailled answer. Looking forward to the release of v14.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Is it Safe to Use the .Tag property ?

Postby MikeHughes on Thu Mar 20, 2014 8:29 am

Hi Pierre,

I should add that I notice that you are using the .Net classes like standard namespaces (ie) MyButton.∆mytag←something

I would warn against this as in some circumstances these "properties can just disappear which is why I developed the Get and Set functions to allow the use of several properties or values to be stored on an object.

The only way to be certain that your custom properties exist in all circumstances is to inherit the class and define your own properties or to use the Tag property which also persists.

Best regards
Michael
User avatar
MikeHughes
 
Posts: 86
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest