Compile error.

Posts   
 
    
npathuru
User
Posts: 17
Joined: 14-Jun-2005
# Posted on: 26-Jul-2007 21:17:35   

I created a simple template called EditControlAscx.lpt and copied this in it:

<%%@ Control Language="C#" AutoEventWireup="true" CodeFile="<%=currentEntity.Name%>.ascx.cs" Inherits="Edit<%=currentEntity.Name%>" %%>

When i build it i get this error:

"The name currentEntity does not exist in the current Context."

Following is the code it generated:

private void __ScriptCode() {
    __outputWriter.Write("<%");
    __outputWriter.Write("@ Control Language=\"C#\" AutoEventWireup=\"true\"  CodeFile=\"");

__outputWriter.Write(currentEntity.Name); __outputWriter.Write(".ascx.cs\" Inherits=\"Edit"); __outputWriter.Write(currentEntity.Name); __outputWriter.Write("\" "); __outputWriter.Write("%>"); __outputWriter.Write("\r\n\r\n"); }

Any suggestions how i can fix this. Thanks.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 27-Jul-2007 04:04:37   

currentEntity doesn't exists, like the error says.

add this to your lpt file

<~ public EntityDefinition currentEntity{ get{ EntityDefinition e = _activeObject as EntityDefinition; return e; } } ~>

To get (at least some) understanding of where these fields come from (_activeObject, __executingGenerator etc) download the source code package for lbll 2.0 and open the CodeGenerator solution. In the LptParser project open DotNetTemplateEngine.cs and scroll/jump to the ProduceCSCode method.

I've modified my copy of lptparser so the generated class inherits from a base class I created (rather than just implement the interface) as to provide common functionality (like CurrentEntity) to all my templates. (a sweeter alternative to 'including' templates)

The objects you have are: (and this is no doubt in a help file somewhere)

StreamWriter __outputWriter IGenerator _executingGenerator Dictionary<string, TaskParameter> _parameters object _activeObject

Hack the planet!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 27-Jul-2007 10:37:56   

It's also documented in the SDK docs wink

If the lpt template is executed in a task which handles all entities (emitType = allEntities), thus loops over the entities, the _activeObject is the current entity (see Lpt templates engine in the SDK docs)

Frans Bouma | Lead developer LLBLGen Pro
npathuru
User
Posts: 17
Joined: 14-Jun-2005
# Posted on: 27-Jul-2007 16:54:40   

Great Thanks. Will look into it. Thanks to both.

npathuru
User
Posts: 17
Joined: 14-Jun-2005
# Posted on: 27-Jul-2007 18:41:38   

Following is the lpt file:


<~ public EntityDefinition currentEntity{ get{ EntityDefinition e = _activeObject as EntityDefinition; return e; } } ~> <%%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit<%=currentEntity.Name%>.ascx.cs" Inherits="Controls_Edit<%=currentEntity.Name%>" %%>


Here is the ascx file it generated;


<~ public EntityDefinition currentEntity{ get{ EntityDefinition e = _activeObject as EntityDefinition; return e; } } ~> <%%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit<%=currentEntity.Name%>.ascx.cs" Inherits="Controls_Edit<%=currentEntity.Name%>" %%>


currentEntity.Name is not getting replaced with the actual entity name in each of the ascx file that is generated. Any suggestions please.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 30-Jul-2007 18:55:10   

You pasted exactly the same code twice. Could you check what the real code was that was outputted? How did you execute the template? (which task etc. please copy/paste frm the .preset file)

Frans Bouma | Lead developer LLBLGen Pro