Reduce the size of the DELPHI2010 program (turn off the rtti reflection mechanism)

Source: Internet
Author: User

Since Delphi2010 enhanced the RTTI reflection mechanism, the compiled program becomes larger because by default Delphi2010 adds Rtti information to all classes (oh, no matter you use it, as if the practical value is really not high, at least I will not use at present). Although the speed of the operation of the program has little impact, but will increase the size of the installation program, which we do not want to see. Is there a way to disable Rtti information so that you can reduce the size of the compiled program? , we found the method from the document.

First, in the project with the compilation instructions to disable Rtti

The disabled method is simple, which is to be in the project (DPR file. Delphi2010 The following definition is added before the uses statement of the project file is the Dproj file, but the DPR file is still the default writing code for the project file:

{Reduce EXE size by disabling as much of RTTI as possible (Delphi 2009/2010)}

{$IF compilerversion >= 21.0}

{$WEAKLINKRTTI on}

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

{$IFEND}

OK, so after recompiling you will find that the EXE file size has been reduced, but this is not enough, please continue to look down.

Ii. reconstruction of Vcl/rtl without rtti information

Here we carry out the key operation, because the VCL and RTL units are still with rtti information, we need to remove their rtti information. Open delphi2010 New project, and save, here we for the convenience of discussion, save it to the C:\nortti directory, under it to build a subdirectory delphi2010, complete the following directory: c:\nortti\delphi2010.

Add all the VCL/RTL units used in the uses section of DPR, hehe, this can be messy, so I put all the unit names in a containing file (. inc file), refer to it (note that this is all the cell names, you only need to keep the cell name when you are really using it), and then click Options on the Project menu to edit the Unit output directory entry value to C:\nortti\ delphi2010. Compile the project, and delete those cell references if you have an error message. (Note: When the JPEG unit is rebuilt you need to copy the files from the Source\win32\vcl\imaging\jpgimage\obj directory to your project directory) and close the project when the compilation is complete.

Tip: You can use the following batch file to produce the list of units mentioned above

@echo off

Del Unitlist.inc

Dir/b "C:\Program files\embarcadero\rad studio\7.0\source\win32\vcl\*.pas" >> unitlist.inc

Dir/b "C:\Program files\embarcadero\rad studio\7.0\source\win32\rtl\win\*.pas" >> unitlist.inc

Dir/b "C:\Program files\embarcadero\rad studio\7.0\source\win32\rtl\common\*.pas" >> unitlist.inc

REM Manually add some system units (we cannot add the entire dir or problems crop up)

echo Sysutils.pas >> Unitlist.inc

echo Types.pas >> Unitlist.inc

echo Variants.pas >> Unitlist.inc

echo Varutils.pas >> Unitlist.inc

Then open the generated unitlist.in file, find and replace all of the?. Pas? for?,?。

Hehe, said so much, everyone a bit dizzy, fortunately, the author provides a project, http://www.zipplet.co.uk/getfile.php/rttidisable.zip, we download down, modify it can be directly used, remember to modify the output directory Yo!

Iii. using the newly generated unit in the project

Open delphi2010, modify the global cell lookup path, because the compiler always looks for the unit sequentially, and we modify it to use the cells we rebuilt.

Tool menu, Options menu, browse Environment Options, Delphi options, Library-win32. Add the full path of our rebuild unit to the front of the library path.

Once this is done, the new project will automatically use the RTTI unit we rebuilt. Finally, don't forget to use the compile instructions in the DPR project to disable Rtti yo!

You can compare the compiled file size, or is very obvious, in addition we can also use UPX, aspack compression, so EXE will be smaller

Reduce the size of the DELPHI2010 program (turn off the rtti reflection mechanism)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.