Solved

Delphi exe size

Posted on 2002-03-25
5
207 Views
Last Modified: 2010-04-04
If I create a new clean application which uses no extra unit my project is about 16kb, if I include lets say inifiles in uses clause the file growns even when I don't use anything from inifiles.pas.
Why does delphi include code from inifiles when it is unneeded ? Is there a way to remove this unused code ?
0
Comment
Question by:bnz
5 Comments
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
Is included because you ask it . The inifiles unit is declared into uses ( by you ) so the compiler add this 'library' into compiled version.
If you don't need some units just remove these from uses section.

If you don't know if use some units or not, just remove one by one and try to run the application . If receive error mesages then undo . Do that for all declared units ( but one be one ) .
0
 
LVL 1

Expert Comment

by:slavikn
Comment Utility
You can make a package. It is very small because is doesn't compile any units. It uses DLLs which are included in the Windows directory. It doesn't work sometimes because a certain DLL may be old...
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 100 total points
Comment Utility
Units can have initializations, that is, code that is executed when loading or stopping the application. These are used to initialize things needed for that particular unit to work. Now, your example IniFiles itself does not have such initializations, but it does include other units: Windows, SysUtils, Classes and Consts. Both SysUtils and Classes do have initializations; SysUtils mainly to provide exception handling and Classes mainly for the streaming system. So that's the code that is added - and executed - to your EXE.

Note that the Forms unit is making your EXE grow about the most. So unless you use it (GUI stuff), you should not include it directly or indirectly if you want to have a small EXE file.
0
 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
Shrink the size of your .EXE using the UPX tool... get the latest version from http://upx.sourceforge.net/
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
hello bnz, you can remove the unneeded Kb by rewriting the units (SysUtils and Classes) and only including the functions and initialization code that you need for your app, but this can take time and requires API knowledge. You could use API and leave out the inifiles unit altogether.

var
IniName: PChar;
CharBuffer: array[0..255] of Char;


IniName := 'C:\App Folder\this.ini';

  GetPrivateProfileString(FormPos,'Top','70', CharBuffer, SizeOf(CharBuffer), IniName);
  {GetPrivateProfileString reads the specified String or gets the lpDefault
  if there is no string to read}
  Top := Str2Int(String(CharBuffer));
  {get the Top and Left for the window position}
  GetPrivateProfileString(FormPos,'Left','70', CharBuffer, SizeOf(CharBuffer), IniName);
  Left := Str2Int(String(CharBuffer));



procedure ShutDown;
var
WinPlace: TWindowPlacement;
begin
WinPlace.length := SizeOf(TWindowPlacement);
GetWindowPlacement(hNoteHandle,@WinPlace);
WritePrivateProfileString(FormPos,'Top',PChar(Int2Str(WinPlace.rcNormalPosition.Top)), IniName);
{WritePrivateProfileString writes to an Ini file}
WritePrivateProfileString(FormPos,'Left',PChar(Int2Str(WinPlace.rcNormalPosition.Left)),IniName);
PostQuitMessage(0);
end;


Are you trying to create an app without the Forms unit?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now