10

i have use delphi xe recently but exe size is very big because of rtti(i think)

howto remove rtti , and can i make my application size as small as delphi 2009 application(490 kb) without comprssion; and what is the use of rtti

Vibeeshan Mahadeva
  • 7,147
  • 8
  • 52
  • 102

5 Answers5

17

In short (full story provided by links in the splash's answer):

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

Note that as of XE6 and newer, this needs to be in each individual unit for which you want to disable RTTI. Before that (XE5 and below) it could be in the DPR file and would apply to all units in the project.

Stefan Glienke
  • 20,860
  • 2
  • 48
  • 102
gabr
  • 26,580
  • 9
  • 75
  • 141
  • +1 for the exact statement, which you would otherwise need to find by digging through the docs as they are mostly geared towards how to use it instead of how to turn it off. – Marjan Venema Oct 20 '10 at 06:58
  • Your RTTI statement, when used on my D2010 results in the compiler error: DCC Fatal Error: E2158 System unit out of date or corrupted: missing TVisibilityClasses. Any suggestions? – RobertFrank Oct 26 '10 at 01:16
  • Only this: http://docwiki.embarcadero.com/RADStudio/en/E2158_%25s_unit_out_of_date_or_corrupted_-_missing_'%25s'_%28Delphi%29 Are you trying to recompile system unit? Maybe you should ask a new question here - more people will see it that way. – gabr Oct 26 '10 at 08:14
  • why this isnt by default off in DLL projects? If there is no performance diffrence – mca64 Sep 27 '14 at 17:46
  • Link: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/RTTI_directive_(Delphi) says: scope: local (the link in the answer is not available anymore) – mjn Nov 17 '21 at 14:25
8

Read the Online Help for Delphi ...

... and search Stack Overflow:

Keep in mind that the $RTTI directive has to be included in every unit where it should take effect. See How can I set the $RTTI directive for the entire project?

Community
  • 1
  • 1
splash
  • 13,037
  • 1
  • 44
  • 67
  • +1 for the links to background info, though it would have been nice had you provided the statement gabr now did directly in your answer. – Marjan Venema Oct 20 '10 at 06:58
7

Your problem is not related to RTTI. If you are talking about relatively small increase (100-200K), this is due to extra functions in RTL (added for Unicode support etc). If you get 500-700K increase or so, then check whether you link VCL UI units (Forms, Controls etc). If you get 3Mb increase, then you've turned on extra debug symbols.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • but i think Unicode is already in Delphi 2009 (basic app only 499 kb ) but theres is no large improvement in Delphi xe vcl (delphi xe app size 800 kb)so ithink the extra 300 kb is mosty form RTTI. and d2007 apps (without unicode is ~350 kb) – Vibeeshan Mahadeva Oct 21 '10 at 06:59
  • And why do you think RTTI was not present in Delphi 2009? – Eugene Mayevski 'Callback Oct 21 '10 at 07:35
  • @Eugene: why do you think it's Unicode functions if the Unicode functions _replaced_ the ANSI ones, rather than being added? And where is the "smart linker" everyone is talking about w.r.t. Delphi? ... if it can't figure out that large parts of the code are not necessary, it's perhaps not so smart after all. – 0xC0000022L Jan 07 '12 at 12:38
  • @STATUS_ACCESS_DENIED Unicode functions didn't replace ANSI functions, but extended them. I.e. for some functions there exist both ANSI and Unicode variants now. – Eugene Mayevski 'Callback Jan 07 '12 at 18:50
  • @Eugene: and aren't those we're talking about still runtime functions only? And if the strings that end up as constants or static data in my binary anyway are Unicode, why doesn't the so-called "smart linker" throw out the functions that uselessly take up space in my binary? I get your point, though. I suppose the way Unicode was implemented (and carried over as a legacy) doesn't make things better. – 0xC0000022L Jan 09 '12 at 20:45
4

It's because some generics functionality has been added to sys units. Generics were added in 2009 but in systems units some classes were rewritten with generics in xe and xe2. imho

Add this flags to reduce the size in dpr file (Project > view source) to each individual unit (as of XE5)*.

{$SETPEFlAGS IMAGE_FILE_DEBUG_STRIPPED or IMAGE_FILE_LINE_NUMS_STRIPPED or
 IMAGE_FILE_LOCAL_SYMS_STRIPPED OR IMAGE_FILE_RELOCS_STRIPPED}

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

(*) Note that as of XE5 and newer, this needs to be in each individual unit for which you want to disable RTTI. Before that (XE4 and below) it could be in the DPR file and would apply to all units in the project.

David
  • 13,360
  • 7
  • 66
  • 130
Alex
  • 41
  • 2
3

I do not think it is RTTI what adds so much size overhead to your application. How do you know it is?

Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156