Two Ways to Reuse Existing Objects In New Projects

The idea for this post was triggered by a comment by MikeH on the last blog post. He requested the feature to have a kind of meta object containing different other objects in a pre-specified manner in order to speed things up for endusers. There are already a couple of features that cover at least similar use cases and I thought I'd highlight them.

1. Project Includes

Project Includes offer a way to include one project into another. A typical use case would be a corporate letterhead where everything is pre-configured from the logo and the addressee to the footer containing your bank account etc. Whenever you change the template, all projects referencing this template are also changed automatically on-the-fly. Great if your corporate design is quite volatile and a great time saver if you have to design an offer template, an invoice template, a letter template and so on and all should look the same.
Usage is straight forward. Just head to Project > Includes, click the “Insert include” button and choose your template. You’ll end up with this:

In the Designer, the objects from the included project are displayed as “locked” in the “Objects” tool window (BTW: the context menu offers a handy shortcut to editing the template). Apart from that, the objects behave like “normal” objects and can now be used across multiple projects:

2. User Defined Actions and Object Model Manipulations

An even more sophisticated method is the addition of a custom action combined with a manipulation of the report’s object model. NB: you need at least the professional edition to be able to change the object model in this way.
The List & Label component has a property “DesignerActions” which can be used to extend the Designer’s functionality. This way, you can add a new action to insert the letterhead into arbitrary objects:

This gives you this new button on the “Project” tab:

The code to execute is written as event handler for the “ExecuteAction” event of the DesignerAction. Writing complex object model code can be a tough task at times – the automatic DOM code generation helps a lot here. You find this little gem hidden as “C# Dynamic Generated List & Label DOM Code” sample. What it does is to take an arbitrary List & Label project, analyze its object model and return the code required to generate exactly this project. So if your plan is to add the ACME logo, you open the corporate letterhead in this sample, select the logo and click the “Generate Code” button. The result is this:
 


From the right hand side you can now easily copy the code that generated your ACME Corp. logo into the event handler. Note – this is automatically generated code which is seldomly very beautiful to look at but very effective as it spares you the time to write it manually ;-).

The “real” handler also has the code to draw the logo circle – once you followed up to here it’s easy to imagine how to extend this further. The result of course is now an easy way to add the letterhead or even just the logo to any project:

Related Posts

Leave a Comment