maandag 1 april 2013

Recursive Indirection

"Recursive indirection". That sounds pretty impressive but I guess it does not mean much to you without some explanation. Here it comes:

You all know how to assign a value to a variable  in Uniface:
vValue = "Hello world"

And you also know how to assign to value of a field to a variable:
WELCOMETEXT.DUMMY = "Hello world"
vValue = WELCOMETEXT.DUMMY

Most of you also know that you can use indirection.
With indirection you have a field that contains the name of another field., and you use this to assign the value of that field to a variable:

WELCOMETEXT.DUMMY = "Hello world"
WELCOMEFIELD.DUMMY = "WELCOMETEXT.DUMMY"
vValue = @WELCOMEFIELD.DUMMY

Not many people know that (in recent Uniface versions) you can do this recursively:
WELCOMETEXT.DUMMY = "Hello world"
WELCOMEFIELD.DUMMY = "WELCOMETEXT.DUMMY"
WHATFIELD.DUMMY = "WELCOMEFIELD.DUMMY"
vValue = @@WHATFIELD.DUMMY

You probably do not need this often, but it can be valuable in complex user interfaces or maybe a software package that is highly configurable. Don't forget to put in some comments when you use this: it is powerful but it does not make your code easy to understand for your fellow developers!