Simplicty and flexibility!

Problems with GetCurrent() and SetStyle() in a subform.

Started by Henry Gondorf
You will need to Sign In to be able to add or comment on the forum!

Problems with GetCurrent() and SetStyle() in a subform.

I am using DE8.5.0.2115.

The problem I am having is to do with sub forms and SetStyle to the record that I am actively on when I scroll down through the sub form. I have used a virtual field “vManip” with the following script: SetVar("RowNr", GetCurrent("RowNumber")-1) + SetStyle(concat("1Stock*#", GetVar("RowNr")), "ArialR8Red").

I want to be able to change the style of a field on the row that the cursor is on but the script changes all the fields that are selected (“1StockRef” and “1StockDesc”) on all the rows. I have tried all day with different combinations and I have deleted and recompiled the script many times but it still will not select the particular row that I want it to. Am I doing something wrong?

Written by Henry Gondorf 27/01/16 at 18:37:07 Dataease [{8}]FIVE

Re:Problems with GetCurrent() and SetStyle() in a subform.

1. The GetCurrent("RowNumber") reports the correct RowNumber most of the time. Due to the intricacies of the DataEase Multiview it can report 2 for row Number one, but it is consistent when it first happen so then you can just deduct one as you have here. It will be easy to spot as you will manipulate the wrong row ;-)

Another problem with GetCurrent("RowNumber") is that you can't use it in OML on the same row as OML doesn't have the correct row context (it only related to its own row, but you can reference any object on that row).

So if you want to use GetCurrent("RowNumber") in OML you need to make a virtual field in the row that simply have it as derivation, and then hide it with Valuloade:event and script hide().

Then you can reference this virtual fields .value in OML and you get the correct Row number.

OK back to the task at hand.

2. There is no need to put the Rownumber in a Global variable, you can just reference it directly.

So SetVar("RowNr",GetCurrent("RowNumber")) is not neccessary.

3. Where to start...he,he.
SetStyle(concat("1Stock*#", GetVar("RowNr")), "ArialR8Red").

* is wildcard. If you use that it will manipulate all Objects that start with whatever you put in front of it. If you do:

SetColor("*","#ff0000","-1","-1") then you will set red font on every object in your form.

SO DON'T USE * in object names or in any derivation if you don't intend to use wildcard.

If you want to Set the style on the current row then simply write.

SetStyle(concat("ObjectIWantToSet#",GetCurrent("RowNumber"),"Style") -- and -1 if you hit it cross eyed.

Its not harder than that.

Written by DataEase 27/01/16 at 20:13:36 Dataease [{8}]FIVE

Re:Re:Problems with GetCurrent() and SetStyle() in a subform.

Thank you for your reply.

Item 1. I am not using this script in OML. It is being used as a derivation in a virtual field, “vManip1”, that I created on the table view specifically for this action.

Item 2. I created the variable “RowNr” so that I could “message GetVar(“RowNr”) pause” and identify that I was accessing the correct row.

Item 3. Where to start…He..He. I specifically intended to use the wildcard “*”. I had given the fields in the table view object names starting with “1” so as not to confuse them with any other fields on the screen with the same name. I had also “object named” two particular fields “1StockRef” and “1StockDesc” which I had already stated. So, I used the “*” after “1Stock” to pick out these 2 fields only. It is irrelevant whether I pick out all the fields or just one: the point of the exercise is to limit the selection to the particular row that the cursor is on. I was not able to do that.

OK. Back to the task in hand.

I have modified the virtual field “vManip1” derivation as per your suggestion “ SetStyle(concat("1StockDesc#",GetCurrent("RowNumber")-1),"ArialR8Red") .” to just change the style of the one field “1StockDesc” and when I change to user view, the field “1StockDesc” is changed in ALL THE ROWS as before. No difference. It does appear to be harder than that.

The derivation seems to fire immediately on opening the form rather than on accessing the row. The second field in from the left is virtual “vRowNr” with the derivation “GetCurrent(“RowNumber”).

Thank you for your kind help with this problem. I appreciate your help and I hope that I am not taking up too much of your time and that it is not “too beginner level” for your expert attention.


Written by Henry Gondorf 28/01/16 at 09:57:36 Dataease [{8}]FIVE

Re:Re:Re:Problems with GetCurrent() and SetStyle() in a subform.

Download Sample

You are right (and wrong) and so am I ;-)

Firstly I applaud your effort and attempt and you were right. You can combine * and # so it is obvious that we can't keep up with developments around here (and that is not a joke, it is so much new functionality, bug fixing, and new features that we the QA/Documentation team can't keep up. There is features that will revolutionize DE forever that hasn't even been properly tested in house and hence haven't even been shown to full Email Support, WebForms in DE85, Remote() reading/writing to data sources, DataEase Server, Deployment Services... it is all there just need final QA, Documentation and gift wrapping.... it will be an exciting year)

But first it is 85 and the matter at hand ...

I misunderstood you and you misunderstood GetCurrent("RowNumber").

GetCurrent("RowNumber") gets the current rownumber from where it is being called so when you put in a vManip in the Subform there will be one clone pr. row so each row will run the same script, hence you get the same style everywhere (must applaud you for using SetStyle() rather than SetColor() too, as it seems a lot of our user don't see the difference and find SetColor() more understandable... ).

DataEase doen't have an event for "active" row as that is how we should have solved what you want properly. 

Record has a GotFocus event but it doesn't work (we have scheduled a OML cleanup but won't happen before 8.5 release) and then we will call GotFocus() all the way up the chain so when a field on a row get focus, the record get focus and the subform get focus etc. This way you get better control.

But for now we have to cheat, or use a work around....

It is not as hard as it sounds.

If you use the mouse you can put the Script on the Subform/Record (we have renamed it sbSubFormRecord (yes, you can rename records now... makes things so much easier...) MouseDown() event.

define "retval" text .

retval := SetStyle(concat("sb*#",GetVar("RowNumber")),"Normal") +wait(0.1)+ SetVar("RowNumber",vCurrentRow.value) +wait(0.1)+SetStyle(concat("sb*#",GetVar("RowNumber")),"Green") .

To honour your brave efforts we do use * (wildcard ;-).

What we do here  is first to reset the last Record that had "focus" and then set the current record,we also save away the rownumber so we know which was last next time.

So far so good...

But what if you Tab into the subform (lots of keyboard bums out there still).

Then you simply need to put the same script on the first field in the taborder in the subform.

define "retval" text .

if GetVar("RowNumber") not= vCurrentRow.value then

retval := SetStyle(concat("sb*#",GetVar("RowNumber")),"Normal") +wait(0.1)+ SetVar("RowNumber",vCurrentRow.value) +wait(0.1)+SetStyle(concat("sb*#",GetVar("RowNumber")),"Green") .


For us that was sbFirstField  so we put the script there.

This should cover it, so then to the million dollar question?

Why don't we have to put it on the rest of the fields?

PS! It seems that the * wildcard doesn't work for row one. It is already reported to the nerds and will be dealt with accordingly.

All the best.

Written by DataEase 28/01/16 at 11:06:23 Dataease [{8}]FIVE