click here for a list of all existing Templot documentation
Important Privacy Information cookie information pre-print options:    

click image to open Templot Club in a new tab
Templot club top logo
looking for Templot? - (free)



 you are not logged in  - Login | Join


receive all messages by email: info


Recent Topics
Front Page  Search  Image Gallery  Gallery Upload  My Account  Members  Open Source  TemplotMEC  Help  
make a donation  
please click: important information for new members and first-time visitors Templot Companion - User Guide
            messages archive on Yahoo
page trail:  Templot Club > Forums > OpenTemplot Project > Suggestion - using compiler directives in the Templot code
Templot web site

                                       Suggestion - using compiler directives in the Templot code
     
 Start new topic   Reply blank   Printer friendly 
  Rate this topic  
AuthorMessage
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
1st message | this message only posted: 22 Jun 2018 01:16
 PM  Reply with quote  Reply blank 
from:
Adrian
 

 

view images in gallery
view images as slides
Hi,
I appreciate that this is going to be a little bit of a nerdy computer programmer issue so please completely ignore this if you have no interest in compiling the open source Templot code, OpenTemplot or TemplotMEC.

Having started to go through some of the open source Templot code I would like to suggest that we start using "compiler directives" in any development. I really do think this will make things much simpler and it will allow the same code to be used in all versions without any modification. To allow this we need to agree on a naming convention to use hence this suggestion. However I'm more than happy to change it if it doesn't suit.

So what am I talking about "compiler directives"?

A little bit of background - at the moment Martin has released 2 different open source versions of Templot, namely OpenTemplot and TemplotMEC. To distinguish between the 2 different versions in the code Martin has programmed it in to show different colours and image on the control pad depending on what version you are running. If you look at the code this is set according to the Application Title, to set the colour it has a statement that says if Application.Title = 'TemplotMEC' then set the colour to one value otherwise set it to a different value. The issue that I can forsee is that if a user downloads the code and decides that he wants to change the title of the application then it will break the code.

With compiler directives we can define a flag that states which version we are compiling in one simple file.

What does this mean in practice?

Basically within the project we can include a file, I have decided to call it version.inc, but it can be whatever you want. I have attached the file I have defined but it is very simple.[post edit - the forum doesn't allow me to post a *.inc file so I've replaced it with an image]



Basically it is defining a flag for the compiler - In this example I am setting a flag "OPENTEMPLOT", you can switch to TEMPLOTMEC or TEMPLOT2 by uncommenting the relevant line.

What you then do is include this definition in any unit/form that works differently for the different versions. You do this by using the INCLUDE statement in the unit file - this example is in the control_room.pas and what it does is just include the text from the file defined - in this case version.inc.



What this means is that when the source code compiles you can define which bit of code is included in the compilation.

In the example below the original code is shown in blue. It depends on knowing the exact name for the application title, if it is exactly 'TemplotMEC' then you will get a yellow background, anything else would be blue. All of this code is included in the compilation.

Now we have defined compiler directives or flag this is where the "{$IFDEF" format takes over in the code. This sets the bits of code to include in the build. Because in version.inc I have selected OPENTEMPLOT you can see that section of code is black and enabled. The TEMPLOTMEC section because it hasn't been defined is shown in grey and disabled.



Hence my suggestion - it doesn't matter if you change the application title it will build the version required from the version.inc file. If we can agree on the definitions in that file then when people update the source code if they use these directives we can have one file that covers all three versions.

Note that in addition to the directive $IFDEF OPENTEMPLOT there is a negative version, $IFNDEF OPENTEMPLOT option says that if OPENTEMPLOT is not defined then include this bit of code.

If anyone is feeling really adventurous then you can include your own flag in the inc file e.g. "TemplotCherry" and then when writing code you can add in your own personalisations. Then in the include file by switching the $DEFINE option it is easy to switch between the standard OpenTemplot/TemplotMEC version and their own version.

Apologies if I'm getting too techy but I do think this would make it easier to maintain common code between the different projects.

If anyone has any queries about this then please raise them in this thread and I will do my best to answer them. Otherwise I apologise for introducing a lot of confusing computer speak to the forum.

Regards

Adrian



__________
message ref: 25086

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
2nd message | this message only posted: 22 Jun 2018 15:50
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
Hi Adrian,

Many thanks for that. :thumb:

I have now added .inc to the allowed attachments.

As you noticed I have made very little use of compiler directives, with only one version until now there didn't seem to be anything to gain.

There are still some issues to resolve in creating a common set of files:

1. You will notice in the .lpr file (which is really just a .pas unit file, but the first to be compiled, numbered unit 0 in the .lpi file):

program templotmec;

{$MODE Delphi}

                     
The name in the program statement is used for the .exe file and for the .res file.

The program statement is the first in the program, and as far as I know nothing can precede it. I tried putting {$IF around several of them but the compiler appeared to ignore the directives and use the first program statement it found, regardless.

At least I think it did, the filename on the .lpi file seems to be relevant too. That file also contains the name of the .lpr file. If these things don't all match, the debugger throws a tantrum and aborts the program.

A program statement without a name identifier isn't allowed, so it obviously plays a part somewhere.

Delphi seems to be far more tolerant about this stuff.

It's interesting that the Dephi converter utility has put the {$MODE Delphi} directive after the program statement and not before it.

2. We also need to change the name in various Alerts and Help notes. You will see that I have now done that by using the placeholder Templot0 in a great many places. These are replaced with the Application.Title at run time. See the title_swap function in math_unit.

Doing it that way allows the placeholder to be in const string literals, and makes it easy to write new ones.

Which means we would need

{$IFDEF abc}

Application.Title:='abc';

in the .lpr file, which means it can't be a common file to other versions, if folks want to create their own names. Which in turn makes the compiler directive redundant.

If Aplication.Title is omitted from .lpr, it can be set the the Project Options instead, but that means the .lpi file can't be common to other versions. It might also be set in a unit in the .inc file, but that still doesn't change the program statement.

At present I can't see a way for all files to be common, and changes made only in the .inc file. :?

Assuming that is, that the .exe file should also reflect the name change. If it doesn't, there is surely too much scope for confusion with different versions of opentemplot.exe.

cheers,

Martin.

__________
message ref: 25088

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
3rd message | this message only posted: 22 Jun 2018 16:26
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
p.s. Adrian,

I have been trying:

{$CONST my_title=othername}
...
...
program {$my_title};
Application.Title:={$my_title};

which I'm sure I used to do years ago in GFA, but I can't find a syntax which works in Lazarus, or any help files about compiler constants. :?

Martin.

__________
message ref: 25089

 
This is topic ID = 3295     Page created at 18:23 (local time)  
You can type a quick reply to this topic here.

Click in the box to begin.


But to reply to an individual message, or to include images, attachments and formatted text, use the reply buttons on each message above.

To start a new topic in this forum, click the Start new topic button below.
To start a new topic in a different forum, click the Forum Jump drop-down list below.

             Start new topic 

 click to jump to a different forum:     Back to top of page

Templot Club > Forums > OpenTemplot Project > Suggestion - using compiler directives in the Templot code
about Templot Club

list recently active topics Templot Companion - User Guide - A-Z Index Templot Explained for beginners Please click: important information for new members and first-time visitors.
indexing link for search engines

back to top of page


Please read this important note about copyright: Unless stated otherwise, all the files submitted to this web site are copyright and the property of the respective contributor. You are welcome to use them for your own personal non-commercial purposes, and in your messages on this web site. If you want to publish any of this material elsewhere or use it commercially, you must first obtain the owner's permission to do so.

The small print: All material submitted to this web site is the responsibility of the respective contributor. By submitting material to this web site you acknowledge that you accept full responsibility for the material submitted. The owner of this web site is not responsible for any content displayed here other than his own contributions. The owner of this web site may edit, modify or remove any content at any time without giving notice or reason.
Problems with this web site? Contact webmaster@templot.com.   This web site uses cookies: click for information.  
© 2018  

Powered by UltraBB - © 2009 Data 1 Systems