Friday, June 21, 2013

x++ series: Where do call Super() ?

For everyone who has ever written a x++ code perhaps noticed to Super() method, but some times it should appear after your code and in another situation may leave it at top, before the code.

For who are new to Super() or confusing about that, let me say it means that "initialize me along with 'this' and alter the rest things". It means that everything you place before Super() will affect that initialization  and each code that placed after Super() just comes up to not alter the initialization but maybe need the objects to be ready to be used afterward or add some new functionality.

It will however more important when you are working with queries.
For example ff you are going to modify the query, by placing the code before the Super() you will make sure that query  is modified just before fetching the data;

The real world situation could be when you want to apply a filter to an existing data source on a form. In this case you have to override the executeQuery() method and place your SysQuery::findOrCreateRange(...) then put Super() at the last line (after your own code).

No comments: