Simplicty and flexibility!


Tips! Writing Re-usable OML

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

Tips! Writing Re-usable OML

OML was interpreted as Oh May I Laugh! (Or cry) in 7.x. 

It promised a lot, but in the end it would simply kill your app. 

In DE8 we have created functions so you can do everything that OML promised directly in the GUI via Virtual fields and ExecDQL.

However, there is one thing that you can only do in OML and that is Event Triggered Action.

True. A Virtual field will be re-derived i.e. cause execute of code on Load, Refresh and when a field that it is dependent on change value but that is it. If you want something to happen on Mouse events etc, you need to use OML.

We have fixed OML exstensively in DE8 and to be honest, with new OML code created fully in DE8 we have experienced no GPF or loss of work. It is possibly a combination of less use (due to the new functionality) and higher stability.

Anyhow, it is a necessary feature of any dynamic application so here are s couple of tips on how to be able to copy objects with code without having to change it.

Since we combine the new functionality with OML we need to reference objects with name. When writing OML directly on the object itself you can leave out the object name and just writhe the method or reference the property.

For instance the code:

hide() . 

Put on the ValueLoaded event of a field will hide it on load. Quite nifty if it is simply a support field. 

If you wanted to use SetState instead you would need to use the object name as SetState("") wouldn't do anything....

Same event:
define "retval" text .-- calling a function need to be allocated to something 
Retval :=SetState(Name,0) .


Would do the same. Obviously meaningless as it is much more code to simply achieve the same, but it lead us on to the real usefulness.

Setting colours in OML is a nightmare as you need to set all the RGB elements for all Properties.

To set the colour, border, fill of a field would look like this.

font.color.red := 10 .
font.color.blue := 44 .
font.color.green := 55 .
fill.color.red := 128 .
fill.color.green := 33 .
fill.color.blue := 133 .
border.color.red := 55 .
border.color.green := 123 .
border.color.blue := 44 .
draw() .


and imagine if you are to change the colour on shade, shine, DipShade etc... NIGHTMARE.

So obviously the way to to this is to use the function SetStyle() where you use the inbuilt Styling feature and simply need to change the style with the added bonus that if you change the style at a later time the changes will be transparent to the app.

define "retval" text .
retval := SetStyle(Name,"MyStyle") .


This simple code use the feature that you can read the current objects name directly in OML and then simply put it back into the function.

Let say this was the code on event MouseEnter of a Button it would change style on enter of the mouse and the only thing you would need to do to change it back was to but the reverse code on the event MouseExit.

When copying this button it would still work.

PS! You will always need to re-compile the code after copying the object, but that't it. The code itself is 100% reusable without any need for adaptation.


Written by DataEase 23/11/14 at 12:22:47 Dataease [{8}]FIVE
DG3_BlogList