Include File Bug?

Posts   
 
    
Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 29-Dec-2005 01:49:45   

I didn't find a post on this so I assume it hasn't been addressed.

When creating lpt templates, if there is more then one include, the included code is not shared across all the templates.

Example Primary Template Entity.lpt

Included in Entity.lpt Helper.lpt Entity_Properties.lpt Entity_Methods.lpt

Helper.lpt contains a handful of functions to make the templates easier. The Entity_ templates are the actual template files.

When compiling Entity_Properties.lpt and Entity_Methods.lpt cannot access the code from Helper.lpt (throwing compiler errors). However if I include Helper.lpt in Entity_Properties.lpt and/or Entity_Methods.lpt the compiler complains about the methods already existing. Also if I copy and paste the Entity_Properties.lpt and Entity_Methods.lpt it compiles without any issues (if it wasn't for my OCD I'd be ok with that).

Has anyone else seen this or have a solution?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 29-Dec-2005 11:41:29   

Yes I think you've found a design flaw in the system.

The problem is this: - EVERY .lpt template gets compiled into a class. So if it's an include template or not, that doesn't make a difference - an included template is mapped into the including template at pre-compile time (template contents is replacing the include statement) - this means that if you include template A in template B and then include template B and template A in template C, you'll get two times teh code of A in C, once directly and once via the contents of B.

There are several ways to work around this: - setup your include code in such a way that it is scoped inside the template class and not as general code. You can do this by including Helper.lpt inside a class definition inside the containing templates, and in the containing templates, you instantiate the helper class first (it will get the name which is the same as the templateid) and then call the methods. - you place the helper.lpt methods in a .NET assembly and reference that instead of templates. This is the prefered method. It is easier to debug the code in this assembly as well, as you can test and debug the code outside a template host, by just creating a simple commandline app or a set of unittests.

Frans Bouma | Lead developer LLBLGen Pro
Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 31-Dec-2005 14:08:13   

Thanks, I'll create a quick assembly.