re-usability of buttons and verification screens question

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
stasKanRich
Posts: 12
Joined: Tue Jun 05, 2018 12:10 pm

re-usability of buttons and verification screens question

Post by stasKanRich »

Hello All!

I am new to C# and having trouble "finding" the tags allocated to my object.

I want to be able dynamically without hardcoding the tag name to be able to pass it on to (a pop up screen or anything else)

So when i select a Tag in the tag security section(see attached picture) i can use in in the script as sender. Tag or something similar. this is probable not a "stock supported" feature.

here is where i am at after fighting with this for some time now:

i have added this to the Tags class(gets a tag from passing it the name - works fine):

Code: Select all

public static T StringToTag<T>(string tagName) where T : class
		{
			Type type = typeof(T);
			FieldInfo[] props = Globals.Tags.GetType().GetFields();
			foreach (FieldInfo prop in props) {
				if (prop.FieldType.Equals(type)) {
					if (prop.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase)) {
						return (T)prop.GetValue(Globals.Tags);
					}               
				}
			}
			return null;
		}

now on a button click script action i do something like:

Code: Select all

	void Button_Click(System.Object sender, System.EventArgs e)
		{
                  var TagName = "TestTag2";
GlobalDataItem tag = Tags.StringToTag<GlobalDataItem>(TagName);
		
	LightweightTag tag2 = Tags.StringToTag<LightweightTag>(TagName);
MessageBox.Show(  tag2.ToString());
                }

i cant find a way to track the assigned tag name or even direct reference to the tag in the button/sender variables.

Please help? is there an easier way to do this?

All i need is a Sender.Tag type reference back to the UI chosen tag to allow me to requse the code and button without making a million instances of the same thing in my projects..



[/color]
Attachments
Untitled.png
Untitled.png (322.06 KiB) Viewed 5438 times

stasKanRich
Posts: 12
Joined: Tue Jun 05, 2018 12:10 pm

Re: re-usability of buttons and verification screens questio

Post by stasKanRich »

After forcing my way...
I was able to get the Tag by "Running through the code with a chainsaw"..

I get the field infos from the sender obj.
Then I either look for data item or dynamic bindings in the sender (depending on obj type)
I then use this data to to comb my way in Globals.Tags info fiends to get my tag...

half a page of code to get the tag associated with the sender without knowing the tag name.

There's got to be a better way !!!! :)

is there? Please :) ?

Derkins.Goblertroter
Posts: 13
Joined: Tue Sep 04, 2018 1:20 am

Re: re-usability of buttons and verification screens questio

Post by Derkins.Goblertroter »

Keep in mind that C# is a statically typed language, if you found a solution to your problem albeit long or complicated, you should celebrate.

Post Reply