Simplicty and flexibility!


Subform + SetStyle


Started by afonso santos
Search
You will need to Sign In to be able to add or comment on the forum!

Subform + SetStyle

Hi all,

I've a form with a subform which I want to change font style of field texto_codigonivel_1 according the value of a field nivel, as follows :

Nivel Value loaded event :

define "act" text .
define "vnivel" number .
vnivel := row1.value + 0 .

if Nivel.value = "0" then
act := SetStyle (concat("texto_codigonivel_1#",vnivel),"verde_alface") .
else
act := SetStyle (concat("texto_codigonivel_1#",vnivel),"sb_negro7") .

end


row1 is a virtual field  with an  instruction Getcurrent ("rownumber") -1, defined in multiview subform as number

Nivel is a field listed for each record holding a value 0 to 6 .

Problem:

At the inicial load page it looks correct.

As we scrool up/down the records, the style is  no longer displayed  according nivel field value.

What am I doing wrong?

Thanks for help

Afonso


Written by afonso santos 26/05/18 at 18:28:48 Dataease [{8}]FIVE

Re:Subform SetStyle


A lot of the features in DE8 is "edging" what DataEase for WIndows was designed to do. 

DFW was desinged in a different time and age where what we want today was just Science Fiction.

The manipulation stuff we did in 8.x is to circumvent these limitations but things might not be as easy as one want.

The problem in a subform is that DE only do the computation in the first and last row and each row is a clone which strictly speaking is not directly related to the record. So when you draw the table first time it will compute all the rows correctly but after that it will only change the look of the first and the last row so when the ones in between move up and down they will retain their style.

The solution around this is to simply redraw styles on entire subform each time it is scrolled.

Back when  we did this we looked into making an onScroll event etc, but figured that we needed to draw the line somewhere as we will replace FRM/OML with HTML/Javascript in DE9 Web onwards.

You will be able to use all FRM/OML in DE9 (as well as Web forms after the release of DE9 Web).


Written by DataEase 29/05/18 at 11:40:30 Dataease [{8}]FIVE

Re:Re:Subform SetStyle

Download Sample

Sorry,was a little quick on the save button.


The solution is to manipulate the entire Subform when there is a scroll.

We have included an application that show the problem and the solution and then the "ultimate" solution where we use the Timer() event on Form to control when to update.

In Maindata2 we simply replace the NewValue event from Maindata1 with a LabelExecDQL("DQL") that run the following DQL.

define "retval" text .

define "vCount" number .

define "vMoney" number .

define "vStyle" text .

vCount := 1 .

while vCount<=10 do

vMoney := GetValue(concat("Money#",vCount)) .

vStyle := "Green" .

if vMoney <0 then

vStyle := "Red" .

else

if vMoney >0 then

vStyle := "Black" .

end

end

retval := SetStyle(concat("SubRec#",vCount),vStyle).

vCount := vCount + 1 .

end

this will change the style on the record object for each row.
red if it is <0, green if it is 0 and black if >0.

in Maindata3 (final version).

We simply run the same DQL from the Timer event.

define "retval" text .

define "NewID" text .

NewID := GetValue("ID#1") .

if GetVar("OldID") not = NewID then

retval := SetVar("OldID",NewID) .

retval := LabelExecDQL("DQL") .

end

Each time the timer is called (10 times a second) it will remember NOTHING i.e. it is a fresh Script event so you need to retain the values you want to check on in global variables with SetVar().

So we simply check if the stored valued for RoWID is the same as the one showed in row1 now. If it is we do NOTHING. if it has changed we run the DQL.

The value here will ALWAYS change when you scroll a Subform.

To make sure we don't get a No updated event when we load a new maindata record we simply create a manip that blank the StoredID.


Written by DataEase 29/05/18 at 12:15:47 Dataease [{8}]FIVE

Re:Re:Re:Subform SetStyle

This is a good sample. But, one of my client running two sub-forms.

DataEase version 8.5.0.2535

ScheduleingFrm (Main form)

.Record1

..all the main form fields

..rScheduleDetails (Sub form one)

...Record1

....All the sub form fields

..rDoNotPlaceData (Sub form two)

...Record1

....All the sub form fields

I am not sure how SetStyle will be configured for this;

retval := SetStyle(concat("SubRec#",vCount),vStyle).


Written by Jeyarajah Arulrajah 02/08/18 at 22:37:31 Dataease [{8}]FIVE

Re:Re:Re:Re:Subform SetStyle

Tried the following with no luck

retval := SetStyle(concat("Record#",vCount),vStyle).

retval := SetStyle(concat("Record1#",vCount),vStyle).

retval := SetStyle(concat("rScheduleDetails.Record#",vCount),vStyle).


Written by Jeyarajah Arulrajah 02/08/18 at 22:43:33 Dataease [{8}]FIVE

Re:Re:Re:Re:Re:Subform SetStyle

Hi Arul.

There is a lot in the FRM object models that left to be desired...

In 8.5 somewhere we did a fix that allow you to change the name of the Record object. Before this it was always called Record when you created it and "magically" renamed to Record1 when you reloaded it the next time... Needless to say this caused a little headache.

Just fixing the Record to Record1 (not it is always Record1 if you don't manually change it) is not enough when you are working with Subforms and OML.

Theoretically you are supposed to class objects in OML but I for one has never really got it working (maybe I'm stupid) so if we struggle with that approach maybe some of  you do too...

This is why we fixed it so you can rename Record objects the same way as you can all other objects.

Having all Record objects called Record1 is a showstopper so if one want to play with them in OML ALWAYS change the name for them to give them unique names before starting the coding.

SetStyle() (all Set functions) are GUI Prism function's and do not adhere to the OML paradigme anyway. They are mainly designed to be used outside of OML to allow "normal" users to achieve the same things as you always could in OML if you knew how to do it and it didn't crash....

SetStyle sill simply match the first object in the document that match the criteria and do the action on that.

The logic is top to bottom left to right so if you move an object one pixel above another it will be before in the object model.

As all objects in a subform is clones of the first row they will all go ahead of the next subform etc.

The Set model has developed over the different versions of 8.x and it now support wildcards as well as # (do action on numbered occurrence).

Set functions won't see or work within a record or a subform, it work plenipotentiary on the form so if you have the same name on a column/object in several subforms it will get confused. But this "weakness" is also its strength.

if you want to for instance change the background colour on all objects in a subform you can simply rename all objects to include a header
sub1CustomerNr, sub1OrderNr,sub1Name etc.

Then you do the setstyle like this:

retval := Setstyle("sub1*","BlueBackground") .

But back to your question.

You can simply rename the record objects in both your subform and amend the code to suit and it should work fine.

I'm not sure which of the models you are using but you can amend the labeldql to make it re-usable for any number of Subforms.

define "retval" text .

define "vCount" number .

define "vMoney" number .

define "vStyle" text .

vCount := 1 .

while vCount<=10 do

vMoney := GetValue(concat(data-entry field2,"#",vCount)) .

vStyle := "Green" .

if vMoney <0 then

vStyle := "Red" .

else

if vMoney >0 then

vStyle := "Black" .

end

end

retval := SetStyle(concat(data-entry field1,"#",vCount),vStyle).

vCount := vCount + 1 .

end

And them amend the OML on SomeText
define "retval" text .

retval := LabelExecDQL("DQL","SubRec","Money") .

Now you will have code that can be re-used on all your subforms as long as you rename them properly.


 


Written by DataEase 03/08/18 at 10:00:20 Dataease [{8}]FIVE

Re:Re:Re:Re:Re:Re:Subform SetStyle

Renamed the subform row to SubFormOne as you were showing on the image.

They tried this code. Still coloring is not working.

define "retval" Number .

define "vCount" Number .

define "vEVV" Text 3 .

define "vStyle" text .

vCount := 1 .

while vCount<=26 do

vEVV := GetValue(concat("EVV#",vCount)) .

if vEVV = "Yes" then

vStyle := "Green" .

Else

vStyle := "White" .

end

retval := SetStyle(concat("SubFormOne" , "#",vCount),vStyle).

vCount := vCount + 1 .

end


Written by Jeyarajah Arulrajah 03/08/18 at 17:20:44 Dataease [{8}]FIVE

Re:Re:Re:Re:Re:Re:Re:Subform SetStyle

Does it work on the first but not on the second, or not at all?

Do you have the styles in your style sheet?


Written by DataEase 03/08/18 at 22:26:32 Dataease [{8}]FIVE

Subform SetStyle

Does not work at all. 

It goes through the DQL and IF logic...etc.

But, it seems like SetStyle is not working.


Written by Jeyarajah Arulrajah 04/08/18 at 05:34:03 Dataease [{8}]FIVE

Re:Subform SetStyle

OK Got It!

When you said style in style sheet. I did not understand. But, after creating a style called Green and White in that style sheet, it worked.

Also, another interesting thing I noticed. You have to display the field within the computer screen view, when we use a field as part of this DQL.
If the field is there, but it is all the way to the right. Then it does not work.


Written by Jeyarajah Arulrajah 06/08/18 at 17:16:51 Dataease [{8}]FIVE

Re:Re:Subform SetStyle

There is a number of rules both in Windows and DataEase for what should be computed.

If a virtual field is outside the screen view it will only be computed if something IN the screen view depend on it.


Windows will equally not send signals to fields that are not visible.


Written by DataEase 07/08/18 at 19:51:49 Dataease [{8}]FIVE
DG3_ForumList