Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code templates - unit name clash between Delphi versions

Different Delphi versions (in my case 2007, XE and XE2) seem to use the same code-template repository, such as ..\Documents\RAD Studio\code_templates. Since XE2 uses namespaced units, this causes problems when one have to use a unit name in a template.

For instance I have a template when I write winbeep which completes to windows.Beep(300, 100); and selects and stops on frequency etc.. This does not compile on XE2 unless I remove the Winapi. part of the Windows unit in the uses clause (or of course add the prefix manually). I have to have the unit name because otherwise SysUtils.Beep gets referred.

I couldn't find an option entry or a registry key or an environment variable specifying the place of the templates. It is not even related to BDSUSERDIR, in fact I don't even have a directory in my computer having the path of BDSUSERDIR (which is ..\Documents\RAD Studio\9.0). Is this my oversight and in fact there's an option to relocate code templates? If not, is it possible to make the IDE use unit aliases in uses clause for new forms?

edit:
Here it is stated that (emphasis by me) "Templates that you create (and templates provided by third party add-ins) are saved by default in the \My Documents\RAD Studio\code templates\ directory." That would imply there should be way to save them in a non-default place. But the article does not mention how.

like image 342
Sertac Akyuz Avatar asked Apr 13 '12 01:04

Sertac Akyuz


2 Answers

You can put your templates in "Delphi installation folder"\ObjRepos\en\Code_Templates to make them visible only on one Delphi version.

like image 167
Mikael Eriksson Avatar answered Sep 24 '22 18:09

Mikael Eriksson


Edit

As Sertac points out in the comments, Template libraries are related to project templates, not code templates. Leaving this answer in place because it may help people looking for ways to structure / share / split their project template repositories.


In Delphi XE2 you have a "Template libraries" option under the "Tools" menu. When you open that, you get this dialog:

enter image description here

The "Add" button allows you to add a folder, the "Properties" button allows you to view and manage the contents of that repository.

So it would seem to me that you can simply copy the template library, change it XE2 specific stuff, and then point XE2 to its own repository. Or you could do that only for the templates that require specific XE2 unit handling.

like image 24
Marjan Venema Avatar answered Sep 21 '22 18:09

Marjan Venema