Simplicty and flexibility!

Enable/Disable based on Global variable using SetStyle(),SetState(),SetVar(),GetVar(),MoveObject()

Started by DataEase
You will need to Sign In to be able to comment on the Blog!

Enable/Disable based on Global variable using SetStyle(),SetState(),SetVar(),GetVar(),MoveObject()

Download Sample!

We got a request from a user on how to control the users access of a form based on something happening in the session rather than using user level etc.

We took the challenge and made this simple application.

We may have gone a little further than he asked but its now point for us spending thousands of hours and pounds on developing functionality if you guys don't use it, and we find that the best way of getting you to use it is to showcase it.


In this sample we use a global variable called SecurityLevel which we set and read with SetVar()/GetVar() which as it happens is internal functions in 8 and not a CDF like the previous SetGlobal()/GetGlobal(). Another great feature with SetVar()/GetVar() is that you set named variables rather than numbered and you can set as many as you like!


A lot of you have never really got the hang of styling, but styling in DataEase for Windows is a great though underused feature. I don't blame you as the previous development team didn't get it either and more or less "ruined" it, but it was fixed in 7.2 and improved upon in DE8 so now it is one of the strongest features to get your design to be interactive.

Styles in DFW which was introduced in 1992! is very much like CSS in HTML just many decades earlier!

A lot of you were fascinated and greatful when we introduced SetColor() because it made it so much easier to change colour on objects. 

Where you before had to use OML and write long scipts like.

myobject, := 128 . := 32 . := 12 . etc...

You could now simply write: SetColor("myobject","#ff0000","-1","-1") to set the Font of the object to Red.

So big improvement!

But big enough? NO!

It is still exstensive work to change the look of a form etc, and the function was/is limited to change the colour on three properties only.
Font, Fill, Border. So what about objects with many many more properties like Tab Controls or if you want to set shadow etc?

Another limitation is that you would have to change all your code if you wanted to change the look, and this is where the brilliance of styling comes in. Simply change the style and all the objects styled with that style will change....

So here SetStyle arrives.

SetStyle("Record1","Disabled") will change the main record for instance.


DataEase use a fixed position matrix for forms. This means that your form will be the same size whatever your screen size. Some of you use zoom to fit the screen but it is not a great feature so very often one end up with forms that is squeezed up into the upper left corner.

For readability it is much better if the content is centralized on the screen, so we use the new MoveObject() function to move the main record object (Record1) to the middle of the screen

MoveObject("Record1","C","C") -- this means move the object to Windows Centre/Centre. If you look at the help text in the Landingpage you see that we use

MoveObject("Instruction","R","T") -- this meanst that the object should move to Horizontal Right and Vertival Top. You can of course also use this function to move objects to an absolute position or relative to the current position.

PS! Small flaw in DFW. Main Record is named Record until first save/close/reload where it is renamed Record1 so if you try to use this function on Record1 it will not work until after you close and reload.

Virtual Fields as triggers!

In DFW 6.x and 7.x you basically needed to use OML to do "magic" and you still can, but we prefer to use OML as little as possible and only where it is great i.e. events. Other than that we prefer to use proper DataEase features like Derivation (field formulas), Virtual Fields and DQL (ExecDQL).

If you are familliar with our samples you will see that there very often is a small field called Manip in them, this is the "naming standard" we use for our manipulator fields same as we use "retval" for the dummy variable we need to call functions in DQL and OML etc.

Virtual fields are triggered (re-computed) as follows:

1. when the form is loaded.
2. when you browse to a new record.
3. when something it depends on change

So it is very easy to control!

a derivation like:

If (FieldA not=blank, SetState("FieldB","SHow"),SetState("FieldB","Hide"))

Will hide FieldB when you load the form and there is no data in FieldA but it will instantly show it when you have entered the data in FieldA.


Last but not least. To complete our "illusion" of a diabled form we simply use 

SetState("ObjectName", "Disable") to write protect the fields when the form is disabled, then we use SetStyle("objectname","Disabled") where Disabled is a style we created that is grey on light grey.

Then we change the heading with SetLabelText("Heading","New text").

PS! If you never understood why buttons, images, labels had "names" before you do now and you should change them into something meaningful (rather than Text1111112 or Button121112) to make your manipulation easier...

We renamed our Heading to Heading and our Buttons to what they do SaveChanges and DeleteRecord.

We also change the style on Record1 and complete the "illusion".

The secret again is in the Manip fields.

Good luck.

Written by DataEase 25/09/15 at 08:54:32