Code Templates - Element Name Collision Between Delphi Versions

Different versions of Delphi (in my case 2007, XE and XE2) seem to use the same code template repository, for example ..\Documents\RAD Studio\code_templates . Since XE2 uses units with names, this causes problems when you need to use the unit name in the template.

For example, I have a template when I write winbeep that ends on windows.Beep(300, 100); , and selects and stops at a frequency, etc. This does not compile on XE2 unless I remove the Winapi. part Winapi. block of Windows in the uses clause (or, of course, add the prefix manually). I must have a unit name, because otherwise SysUtils.Beep will be passed.

I could not find the parameter entry or registry key or environment variable that determined the location of the templates. It is not even associated with BDSUSERDIR , in fact I don’t even have a directory on my computer with the path BDSUSERDIR (which is ..\Documents\RAD Studio\9.0 ). Is this my supervision and is it really possible to move code templates? If not, is it possible to use IDE aliases in the use section for new forms?

change
It says here that (highlighting by me) β€œThe templates you create (and templates provided by third-party add-ins) are saved by default in the \ My Documents \ RAD Studio \ code templates \ directory." This implies that there should be a way to save them in a place other than default. But the article does not mention how.

+6
source share
2 answers

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

+6
source

Edit

As Sertac points out in the comments, template libraries are associated with project templates, not code templates. Leaving this answer in place because it can help people look for ways to structure / share / share project template repositories.


In Delphi XE2, you have the "Template Libraries" option in the "Tools" menu. When you open it, you will get this dialog box:

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 this repository.

So, it seems to me that you can just copy the template library, change its XE2-specific things, and then point XE2 to your own repository. Or you can do this only for templates that require specific processing of the XE2 block.

+2
source

Source: https://habr.com/ru/post/913096/


All Articles