Reduce the size of Delphi 2010/delphi XE compiled files

Source: Internet
Author: User

1. 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}

2.realease Mode compilation

3. Remove the Debug information

4. Compress with UPX, Aspack
====================================================
1. The referenced unit will affect the EXE and DLL size, the uses of the unwanted units removed, can be smaller.
Of course, if the SDK is developed directly, it is the smallest.

Sysutils.pas System.pas Sysinit.pas There are a lot of common variables and type definitions that you can't use, you can
Make a copy of the variables, functions, and types you want to use in your program to another PAS file of the same name, not at compile time.
Delphi's integrated environment is compiled with the command line DCC, note that your new base library PAS will be included in the
such as Dcc32-q-ddll System.pas sysinit.pas myproject.dpr-m-y-z-$D-
One of the System.pas Sysinit.pas is the type definition, function, etc. dug out from the original PAS.

First, volume testing, Comparison

Environment: delphi2010 + vclskin5.4 + dev5.0
1. delphi2010 Single Window
796KB
2. delphi2010 Single Window + button + text
820KB
3. delphi2010 Single Window + Vclskin
1.13MB (skin file not loaded), 1.16 (load skin file)
4, delphi2010 + vclskin5.4 + dev5.0 (Cxbutton + cxtext)
1.8MB
5, delphi2010 + vclskin5.4 + dev5.0 (Cxbutton + cxtext + cxgrid)
4.18MB------
6, delphi2010 + vclskin5.4 + dev5.0 (Cxbutton + cxtext + cxgrid) +fastreport
5.67M to 6.67MB
Second, the reason
1. Widestring and Rtti used by delphi2010
Widestring makes the string length twice times the original, but the growth volume is limited
Rtti is the main reason
2. Dev
A, the use of skin
Version 5.0 when Qtgrid is used, the cxlookandfeels is automatically introduced, cxlookandfeelpainters
Sometimes the unit in the skin to remove the effect is not very small, you can re-install dev, installation time without selecting the skin, you can save 2M
B. Print is used
5M to 9M
Third, the method of reducing Delphi volume
1. Close Rtti reflection mechanism
Since the introduction of the new Rtti reflection mechanism in Delphi2010, the compiled program will become very large, because by default Delphi2010 adds a reflection mechanism to all of the classes. And our project does not always need to use this function, so we can easily use the following method to disable Rtti reflection, so as to greatly reduce the file volume.
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}
-------------measured,
1.1 Environment, file size is 750KB;
1.2 Environment, 774KB;
1.3 Environment, size is 1.10MB (load skin file)
English: Http://www.zipplet.co.uk/index.php/content/article S_programming_delphi2010rtti
2. Turn off debug information (default is OFF)
linking, Debug information, Options, Project, disabled
Test:
disabled:11.6mb
An DISABLED:31.2MB
Iv. Other methods
1. Reduce the size of the Delphi application
Http://hi.baidu.com/51elv/blog/item/5637a5cff0ef14 31f8dc6124.html
01) Use the shell tool (e.g. upx,aspack, etc.)
02) Use KOL
03) do not use VCL to write programs
04) Using ACLs (API Control Library)
05) Use Stripreloc
06) Removal of the operation of debugging information and TD32
07) write the allowable code in the DLL
08) do not place the picture on the Form at design time, but load it at run time
09) Use compressed images (use JPG instead of BMP)
10) Reduce the attributes in the DFM file
(Refer to the following link "How to make your EXE file more portable")
One) use the Tstringlist replacement by ~lom~
Use of the Minireg-tregistry replacement by Ben Hochstrasser
V. Other articles
dev compiler exe
http://www.devexpress.com/Support/Center/p/Q243794. aspx?searchtext=cxlookandfeels&p=t1| P0|0

Reduce the size of Delphi 2010/delphi XE compiled files

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.