Board index » delphi » Optimizing my EXE file

Optimizing my EXE file

Hello !

I made a very little program in delphi (the source code+ICO file+forms
are only 24KB) and after I compiled it the EXE file is 250KB.
I'm almost sure that this program can be much smaller.
So: how can I compress this EXE file ?

Uri Hartmann
send the answer please to my email too:hartm...@netvision.net.il

 

Re:Optimizing my EXE file


I think if you are using 16-bit Delphi, you can try using a program from
PKWare.  Or you can try turning off all debugging options and rebuild the
whole project.

Re:Optimizing my EXE file


Quote
Uri Hartmann wrote:
> I made a very little program in delphi (the source code+ICO file+forms
> are only 24KB) and after I compiled it the EXE file is 250KB.
> I'm almost sure that this program can be much smaller.
> So: how can I compress this EXE file ?

Remember that if you have any forms in your exe then you'll get at a
minimum roughly 150-200k just from the VCL inclusion. If you want to
make it any smaller in size you can do some of the following

1. Under Delphi 1 run the W8LOSS.EXE (\Delphi\Bin) against the EXE. This
removed duplicate chains
2. Turn off all debugging and rebuild the entire project (not much
savings at all in your case)
3. Look at something like Shrinker from Blink, Inc that compresses your
exe and then expands it on the fly at runtine.

Mark
AppVsiion

Re:Optimizing my EXE file


Hello. This is Hiro.

Uri Hartmann <hartm...@netvision.net.il> wrote in article <32ce30b5.4527...@news.netvision.net.il>...

Quote
> I made a very little program in delphi (the source code+ICO file+forms
> are only 24KB) and after I compiled it the EXE file is 250KB.
> I'm almost sure that this program can be much smaller.
> So: how can I compress this EXE file ?

You can make a small EXE file if you write a source with WinMain and
WinProc functions as a C++ programmer does. It means not to use VCL in
your program.
Following program just shows a form. And it closes itself when it receives
the WM_DESTROY message ( = when a user click the close button in the title
bar).

i.e. --------------------------------------------------------------------------

{ This Program is for Delphi 2.0/2.01/2.0J/2.01J                            }
{ Save this as 'SmallPrg.dpr' and type 'dcc32 SmallProg.dpr' in the command }
{ line to compile it.                                                       }
{ You can compile it in Delphi's IDE, too.                                  }

program SmallPrg;

uses
    Windows, Messages;

const
    AppName = 'SmallPrg';

function WindowProc
(Window: HWnd; AMessage, WParam, LParam: Longint): Longint; stdcall; export;
begin
    WindowProc := 0;

    case AMessage of
    wm_Destroy:
        begin
            PostQuitMessage(0);
            Exit;
        end;
    end;

    Result := DefWindowProc(Window, AMessage, WParam, LParam);
end;

{ Registering Windows calss }
function WinRegister: Boolean;
var
    WindowClass: TWndClass;
begin
    with WindowClass do begin
        Style := cs_hRedraw or cs_vRedraw;
        lpfnWndProc := @WindowProc;
        cbClsExtra := 0;
        cbWndExtra := 0;
        hInstance := System.HInstance;
        hIcon := LoadIcon(0, idi_Application);
        hCursor := LoadCursor(0, idc_Arrow);
        hbrBackground := HBrush(Color_Window);
        lpszMenuName := nil;
        lpszClassName := AppName;
    end;
    Result := RegisterClass(WindowClass) <> 0;
end;

{ Creating Windows class }
function WinCreate: HWnd;
var
    hWindow: HWnd;
begin
    hWindow := CreateWindow(AppName, 'Delphi Small Application Window',
                 ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
                 cw_UseDefault, cw_UseDefault, 0, 0, HInstance, nil);

    if hWindow <> 0 then begin
        ShowWindow(hWindow, CmdShow);
        UpdateWindow(hWindow);
    end;

    Result := hWindow;
end;

var
    AMessage: TMsg;
    hWindow: HWnd;
begin
    if not WinRegister then begin
        MessageBox(0, 'Register failed', nil, mb_OK);
        Exit;
    end;
    hWindow := WinCreate;
    if hWindow = 0 then begin
        MessageBox(0, 'WinCreate failed', nil, mb_OK);
        Exit;
    end;

    { Message Loop }
    while GetMessage(AMessage, 0, 0, 0) do begin
        TranslateMessage(AMessage);
        DispatchMessage(AMessage);
    end;
    Halt(AMessage.wParam);
end.
-------------------------------------------------------------------------

My compiler (Delphi 2.01J) outputs an 8192 bytes executable file because
it doesn't include VCL which is very convinient and has quite big size...

-----------------------------------------------------------------------
Mail: shima...@annie.co.jp   Home Page: http://www.annie.co.jp/~shimaden/
Hiroyuki Shimada
-----------------------------------------------------------------------

Re:Optimizing my EXE file


I'm quite new to delphi, but I believe that if you're that desperate, you
can make a new
VCL, strip out every component that you don't use and recompile using that.
You can have several builds of VCL with different contents and just load
whichever is appropriate to your current project.

Of course this will only work if Delphi builds the entire VCL into every
executable rather than just the functionality required to resolve all of
the links.

Uri Hartmann <hartm...@netvision.net.il> wrote in article
<32ce30b5.4527...@news.netvision.net.il>...

Quote
> Hello !

> I made a very little program in delphi (the source code+ICO file+forms
> are only 24KB) and after I compiled it the EXE file is 250KB.
> I'm almost sure that this program can be much smaller.
> So: how can I compress this EXE file ?

Re:Optimizing my EXE file


In article <01bc0200$e3cf4b00$7d14a...@sumatra.unidec.co.uk> "David O'Rourke" <dav...@unidec.co.uk> writes:

Quote
>I'm quite new to delphi, but I believe that if you're that desperate, you
>can make a new
>VCL, strip out every component that you don't use and recompile using that.
>You can have several builds of VCL with different contents and just load
>whichever is appropriate to your current project.
>Of course this will only work if Delphi builds the entire VCL into every
>executable rather than just the functionality required to resolve all of
>the links.

... which, in fact, it does do.  That's the so-called "smart linker."

Quote
>> I made a very little program in delphi (the source code+ICO file+forms
>> are only 24KB) and after I compiled it the EXE file is 250KB.
>> I'm almost sure that this program can be much smaller.
>> So: how can I compress this EXE file ?

Imagine, if you will, that your program is built upon a very complete, very
robust foundation -- capable of handling all kinds of exceptions, being a good
Windows citizen, etc. etc.  A foundation strong enough to support both trivial
programs and commercial applications.  A foundation that contains more code
than you might require, but all the code that commercial apps would require.

In the long run and these days, 250K is simply an inconsequential amount of
space, especially once the file is compressed.  I'm sure that you could
squeeze out more things and make the file smaller, but for what?  :-/

Re:Optimizing my EXE file


On 14 Jan 1997 09:46:04 GMT, "David O'Rourke" <dav...@unidec.co.uk>
wrote:

Quote
>VCL, strip out every component that you don't use and recompile using that.
>You can have several builds of VCL with different contents and just load
>whichever is appropriate to your current project.

Uhh, you don't want to even TRY to do that.  The object heirarcy is
very bizzare, and usually confusing.  Don't do it, it'd take you
months/years to finish!!!  The thing that you should notice as you
further develop is that the file size doesn't increase very rapidly
after that first initial jump...  Also make sure that a tdstrp32
[exename] doesn't decrease the filesize.

Quote
>Of course this will only work if Delphi builds the entire VCL into every
>executable rather than just the functionality required to resolve all of
>the links.

Unfortunately, I don't believe the Delphi linker properly strips out
the dead code if its part of an object that is either directly or
indirectly accessed in you program.

trepalium

Re:Optimizing my EXE file


Trepalium <Trepal...@null.net> wrote

Quote
> Uhh, you don't want to even TRY to do that.  The object heirarcy is
> very bizzare, and usually confusing.  Don't do it, it'd take you
> months/years to finish!!!  The thing that you should notice as you
> further develop is that the file size doesn't increase very rapidly
> after that first initial jump...  Also make sure that a tdstrp32
> [exename] doesn't decrease the filesize.

If it's such a dumb idea, then why did borland make it so easy to attempt?
You just go to the Component Menu, Install Option and remove the modules
that you don't want.
You can copy the .dcl files to wherever you want to keep them, and Open
Library lets you choose the one you want.

I've never tried it but it can't be that bad surely.

        David

Re:Optimizing my EXE file


What?  Delphi's compiler has always stripped out the code for all
un-used methods and properties.  This is no Visual Basic interpreter
we're talking about.

Re:Optimizing my EXE file


What?  Delphi's compiler has always stripped out the code for all
un-used methods and properties.  This is no Visual Basic interpreter
we're talking about.

Re:Optimizing my EXE file


When you guys reply to questions regarding the Borland product Delphi,
please edit out the alt.online-service.delphi newsgroup.
"Online-Service" does not mean "Online-Technical-Support." All
questions asked there are referred to your groups.  We'd hope you'd do
the same.

On 29 Jan 1997 10:00:33 GMT, "David O'Rourke" <dav...@unidec.co.uk>
wrote:

Quote
>Trepalium <Trepal...@null.net> wrote
>> Uhh, you don't want to even TRY to do that.  The object heirarcy is
>> very bizzare, and usually confusing.  Don't do it, it'd take you
>> months/years to finish!!!  The thing that you should notice as you
>> further develop is that the file size doesn't increase very rapidly
>> after that first initial jump...  Also make sure that a tdstrp32
>> [exename] doesn't decrease the filesize.

>If it's such a dumb idea, then why did borland make it so easy to attempt?
>You just go to the Component Menu, Install Option and remove the modules
>that you don't want.
>You can copy the .dcl files to wherever you want to keep them, and Open
>Library lets you choose the one you want.

>I've never tried it but it can't be that bad surely.

>    David

Other Threads