Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reduce .exe size 5

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
0
0
AU
Is there any way to reduce the .exe file for a delphi application?

All my code is within one page (about 4000 lines of code). Will splitting some of it up into different units reduce the size of the .exe file? Is there any other way to reduce the size?




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
AP81,

is there a specific reason why you want a smaller .exe?

--------------------------------------
What You See Is What You Get
 
Splitting the code will not reduce the EXE size.

Be sure you have NOT checked "Project Options/Linker/Include TD32 debug info".

Checking "Project Options/Compiler/Optimization" and unchecking "Project Options/Compiler/Stack Frames" can reduce the EXE size a very little bit (or not... optimization is for speed, not for size).

In a 4K lines source, most of the EXE size is due to the VCL, not your code. If you dont need the VCL, write a non-VCL program. No free lunchs here: what your are gaining in EXE size you are paying in hard work, actually a very expensive lunch :).

As Daddy asked: is there a specific reason why you want a smaller .exe?

buho (A).
 
I just wanted to be able to fit my application on a floppy. It is now 1.58 MB.

I was going to write a couple of seperate class files, however I was told (by the manager) to keep the code as simple as possible so other people could easily pick up on it. I thought the separating code into units may have reduced the exe file size.

Thanks all.






------------------------------------
There's no place like 127.0.0.1
------------------------------------
 

That is a very good reason.

The manager is absolutly and totally wrong. Long sources are more difficult to understand that well structured sources, splitted in logical units.

But splitting your sources will not reduce the EXE size, and adding classes to have it better encapsulated can actually make it a little bigger.

Apparently, your solution is an EXE compressor.

buho (A).

Note: I'm in some way surpressed with a 4k lines source code spawning 1.5 MB... but it depends on what components are you using. I need over 20k lines to spawn 1.5 MB (no data aware components included adn checked with D5).

 
Hi,

I've had a similar problem.

I wrote a console application, and it was about 100 lines, and it was quite big. I hoped that using console would reduce the size, but it was still at least 400k if not closer to 800k. For what it does I think about 60k is more than enough size.

(I don't have it with me at the moment).

It was a simple utility to read the filesize of different directories. And I had to use sysutils or something, but just for one function. Is there not a way that you can just use 'what you need' and leave the rest?

o__
,_.>/ _
(_)_\(_)_______
..speed is good
 
Actually, the linker will link only what you are calling, how many procs and functions are defined in an unit are of no consecuence.

With all due respect Canderel, you made something wrong.

Check the code I'm adding here. It is a 42 lines console app.

Compiled in the right way (NO "TD32 info") the EXE is 41.5 K in size.
Compiled with "TD32 info" checked the EXE is 646 K.

Have you sure you unchecked "Include TD32 debug info"?


Code:
// ---  CONSWEEP.DPR

program consweep;

{$APPTYPE CONSOLE}

uses
  SysUtils;


function SweepDir(Dir : AnsiString) : cardinal;
  var
    SR    : TSearchRec;
    Res   : integer;
    Files : cardinal;
  begin
    Files := 0;
    if Length(Dir) > 0
      then if Dir[Length(Dir)] <> '\'
        then Dir := Dir + '\';
    Res := FindFirst(Dir + '*.*', faAnyFile, SR);
    while Res = 0 do
      begin
        if (SR.Name <> '.') and (SR.Name <> '..')
          then Inc(Files);
        Res := FindNext(SR);
      end;
    FindClose(SR);
    SweepDir := Files;
  end;

var
  Dir   : AnsiString;
  Files : cardinal;
begin
  if ParamCount > 0
    then Dir := ParamStr(1)
    else Dir := '';
  Files := SweepDir(Dir);
  WriteLn('-------------------');
  WriteLn('Directory: ', Dir);
  WriteLn('Files: ', Files);
  WriteLn('-------------------');
end.

buho (A).
 
The only thing I can add is only include in the Uses statement the dpr's you want so if you are not using any dialogs take this out etc. You will have to do this for each unit you are using
 
AHHHH!

I never knew what TD32 is! (never really bothered to check, but I'll have a look)



o__
,_.>/ _
(_)_\(_)_______
..speed is good
 

"TD32 info" will add all the debugging info to the EXE file. It is used for the (legacy?) TD32 Borland debugger.

99.9999% of developers have not need to check it.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top