Maarten Van den... · Jul 18, 2017

Trigger a class compilation

Hi all,

I was wondering if there is any way to trigger the compilation of a class based on the compilation of another (unrelated) class. For example:

Class 1 = test.class

Class 2 =

Class 3 = test.class.type.two

Every time class 2 or class 3 is compiled in Studio I would like to have class 1 automatically compiled as well.

The reason I need this is because class 1 has a method with CodeMode set to objectgenerator which generates some code based on what is found in classes 2 and 3.

0 546
Discussion (8)2
Log in or sign up to continue

Thanks. This worked perfectly. Is there any list available with methods like this one? The Caché documentation does not contain any results for a search on OnCompile and even looking in the source code it's only used once in %SOAP.WebBase. How do you even know this exists?

It looks like this only checks if the dependant class exists and is properly compiled, but does not actually trigger a recompile of that class.

Use your own custom Projection, put it into your primary class, it runs every time you compile your primary class, in the code you can do whatever you want, e.g. compile other classes.

The name is not important. This method is an method generator, so it runs during compilation. But as it produces no code, the method does not get generated.

You can use method generators:

ClassMethod OnCompile() [ CodeMode = objectgenerator ]
    do $system.OBJ.Compile("class")
    quit $$$OK

If method generator produces no code, then it would not be created, only ran at compile time.

True. But also, if you recompile a set of classes (e.g., by compiling a package), then we look through for dependencies like this and make sure to compile the independent class before the dependent one.