I am looking how to detect if an instance of a control template is already populated on a window procedure.
Right now I am writing a control template which add some code in the data section. If multiple instances are implemented on the same window these will create duplicated labels.
So my idea to make my #AT(%DataSectionAfterWindow),PRIORITY(5000)
conditional in some way that it won’t do anything if the first instance of the same template already has done this. Is this possible and if so how?
The nice thing about the second option is that it will work in a much broader range of circumstances. Note that this example works when your template cares about others in the same procedure. If you need to check globally, then just drop the %Procedure portion of the %CustomFlag.
Your suspicion was correct, the first option didn’t work. It appeared that for the only instance
%ActiveTemplateInstance=2 in the first procedure I tried. Probably because I added, removed and added again my control template.
The second solution will work I guess. Couldn’t test it yet because I overlooked some other stuff I need to reckon with when multiple instances are used. Will do that next week. I also will play what happens after a second instance is added and the first one is removed.
BTW I did’t know the symbol %CustomFlags, it isn’t in the documentation. But I found it declared in CW.tpl and ABChain.tpl. Useful to know it is available.
Thank you, but my goal is to allow multiple instances, but also to prevent that some code is generated twice. For example the generation if local variables. The solution Mike posted works for me.
Fair enough. Attached is a template which works in C6 so should work in later versions, which gives me info about a procedure and the app.
Load the global template first so it knows what viewer (notepad) you want to use, then drop the procedure extension onto the procedure you want to know stuff about. I find it quite useful, maybe others will which can give an insight into how the templates organise themselves.
I try to investigate this template next week. On first sight it can be useful to learn how the templates work together. I found that it can make a difference where I place some code how for example the shipping Browse template decides to put some code as well or not.
Or without UNIQUE and check #IF (ITEMS(%MultiSymbol) = 1) after #ADD to know its the first one. Also can check #IF (INSTANCE(%MultiSymbol) = 1) later after #FOR/#FIX to know its first.
Items was what I was trying to remember the other night but couldnt remember, thats the problem with being poisoned, I struggle to even remember what I wrote 5 mins ago in a previous embed sometimes, which makes programming virtually impossible.