How can I set the $RTTI directive for the entire project?
Asked Answered
Y

5

5

I'm working on migrating an old project from Delphi 2007 to Delphi 2010. One thing I've found is that the resulting executable has more than doubled in size, and the original was already quite big. (Over 50 MB.) I suspect that a lot of it has to do with extended RTTI.

Since the project predates Delphi 2010, it doesn't use extended RTTI anywhere, and I'd like to be conservative about including it. Is there any way to use the Project Options dialog to globally set {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} as the default? I'd have expected there to be an option for this (and for $WEAKLINKRTTI) somewhere, but I don't see them.

Does anyone know if this can be done from the "Additional options to pass to the compiler" field, or some other way? I'd really prefer not to have to add an include file to every single unit in the project, as there are a few thousand of them...

Younts answered 14/1, 2010 at 23:31 Comment(0)
I
7

The behavior of the $RTTI directive has been changed since XE6 because actually it was a bug because it was supposed to be local to the current unit (and it was actually documented as that since Delphi 2010).

Also it could have fatal affects using the directive at all even in one unit because due to the bug it basically switched a global flag affecting the following units (as in the order of compilation).

Intolerance answered 11/12, 2014 at 16:35 Comment(0)
P
4

In a comment on Mason's own blog, in response to a comment of mine, Mason answered this question.

Try putting these two lines at the top of your DPR, before the USES clause:

{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}

This will make sure that no RTTI gets generated for your own code or any third-party libraries you use, unless they’re in a unit where RTTI generation is explicitly enabled. You can’t turn it off for the RTL or VCL, but that shouldn’t add very much to your size anyway.

Procne answered 5/1, 2011 at 11:42 Comment(0)
L
3

You can try with the dcc32 –$weaklinkrtti command-line option. (like {$WEAKLINKRTTI ON}).
But that has not the impact of {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} in each unit.
Your best bet would be to have it at the top of each unit in an include file.
But then it wouldn't do it for the VCL/RTL which would still be inflated....

Update: Also make sure you compare what's comparable. For instance verify if you don't include debug information in the Linker Options in the new D2010 project where you may not have it in the D2007 one...

Leitman answered 15/1, 2010 at 3:7 Comment(2)
I tried putting -weaklinkrtti in the "Additional options to pass to the compiler" field in Project Options, but it just gave a compiler warning: [DCC Warning] W1030 Invalid compiler directive: '–weaklinkrtti'.Younts
Sorry Mason, you have to include the $ in the project options. My bad. Edited answer.Leitman
O
1

Are you certain this is caused by the new RTTI info? While it's a lot of data it shouldn't really double the size of your application.

Check that it's not including debug info in the release build executable. (Project options -> Delphi Compiler -> Debug information should be False)

As for the question, I use {$WEAKLINKRTTI ON} before the uses clause in the dpr file and it seems to work fine.

Octillion answered 15/1, 2010 at 9:45 Comment(0)
M
0

I don't know of such an option, but I still would use an include file.

I wont be a problem for any experienced Delphi programmer to write a small program to add an {$i ProjectIncludeFile.inc} to any unit in your folders (immediatly after the unit line).

And that way you can use it for whatever purpose you like.

I myself use if f.i. to set a WriteTempFiles compiler directive (which I use f.i. to save stringlist contents at various places when developing the program), that way I can disable it in one place when the program is ready for deployment.

Since most of my projects involve multiple executables and/or dll's, this is the easiest way to accomplish this globaly for the whole project.

Menhaden answered 15/1, 2010 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.