Solved

Reducing the Exe Size

Posted on 1999-01-11
13
300 Views
Last Modified: 2010-04-06
Hi all Delphi lovers,

  I am new in Delphi, and now having some problems with Forms unit.
  Even if I write a simple program(containing no form) the exe size is 170KB.(it really does not affect if you turn off some project options, the exe size is nearly the same). My problem is that I have to use Forms  unit in my uses clause to have the application object. Because every project that is written in Delphi must have an Application object created. But when I include Forms unit the exe size is over 170 KB. How can I reduce the size...

Thanx
0
Comment
Question by:kyl011199
  • 3
  • 2
  • 2
  • +5
13 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1355874
If the only reason that you include the Forms unit is because you want some function that TApplication provides, then you can probably find another way of doing it.

For example, if you only use Application.Terminate, then you could use PostQuitMessage(0) instead.

Or if you use BringToFront, you can instead use SetForegroundWindow.

So tell me what properties/methods/events you want to use, and I'll see if I can find an API equivalent.

You *can* write a Delphi program without the Forms unit and without the Application object.

My personal thoughts on this are "Who cares about 100k anyway?". Is there a genuine need to make the exe smaller?

Cheers,
Phil.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1355875
You could also use packages. In this way the .EXE itself is small (though you do need to distribute the packages which can be large) - this is beneficial of you have a number of EXE's which can share the same packages.

Cheers,

Raymond.

0
 

Expert Comment

by:dejohn99
ID: 1355876
170 K is about the smallest you can make a Forms based application.  

When you consider that even the original single density floppy diskettes (okay, I'm dating myself) had 180K, who cares?  Now multi-gigabyte hard drives are the norm and cost less than what that original 180K floppy drive did.  

I'd say that unless there is a real need, find somewhere else to waste your time, like laser tag.  It's a lot more fun than squeezing individual bytes out of a small applet.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1355877
Hmm. My smallest Delphi program is 15 KB, of course without forms.pas. If you really NEED your program to be this short, it is possible. But a lot of work.
Just remove all units (that have a form) from your project and in the menu click on "new->unit". Then remove the forms.pas uses in your project file and remove also all Application.* from your project file. That's all...  :-)

I'm with Phil in this point. Tell us why do you need the Application object?

Regards, Madshi.
0
 

Expert Comment

by:koger
ID: 1355878
I think I've heard of a program called sapper or zapper, which could reduce the filesize with 60%
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1355879
Use this EXE packer:
www.alenka.spb.ru/aspack/
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:BlackMan
ID: 1355880
Aargh, meant it as a comment, sorry!
0
 
LVL 1

Expert Comment

by:hustch
ID: 1355881
Madshi is right, unless you need access to the Application object, just remove the code. The following "program" is only 15.5kb

program Test;

uses
  Windows;

var
  Msg       : string;

begin
  Msg := 'This is a Test';
  MessageBox(0, PChar(Msg), 'Small exe test', MB_OK);
end.
0
 

Author Comment

by:kyl011199
ID: 1355882

Hi everybody,

  I think I must use (as one of you suggested) straight api instead of using Delphi VCL which is a long way.
  I am using some properties of Application; Application.Terminate, Application.OnException,  and the main part of the application object which is the message loop. Meantime I searched the net to find some exe packer programs, but none of them was shareware and they all add some dialog messages in the vey first beginning of the compressed exe.


From your comments I understood that VCL always has some overhead but provides easy programming then I decided to write all the code in native Api. So who deserves the points.

Thanks you all for your suggestions

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1355883
The EXE packer which I mentioned in my com.., eh, answer, is free with no nag dialogs...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1355884
I think Philip deserves the points, because he was the first one.

Here something you can use instead of TApplication.xxx:

procedure HandleMessage;
var msg : TMsg;
begin
  if PeekMessage(msg,0,0,0,PM_REMOVE) then begin
    TranslateMessage(msg); DispatchMessage(msg);
  end else WaitMessage;
end;

procedure ProcessMessages;
var msg : TMsg;
begin
  while PeekMessage(msg,0,0,0,PM_REMOVE) do begin
    TranslateMessage(msg); DispatchMessage(msg);
  end;
end;

Like Philip told you, instead of Application.Terminate you can use PostQuitMessage(0) or even ExitProcess(0).

I'm not sure about Application.OnException.

Regards, Madshi.
0
 

Author Comment

by:kyl011199
ID: 1355885

I downloaded the packer BlackMan suggested. And tried the aspack.exe, its compression ratio is %45, very fast (compressed exe runs very fast), really good and does not have dialogs.

Madshi says that Philip deserves points. I aggree ,
Please resubmit your comment as answer,

All you are great, but I want to especially thank to BlackMan, because I spent 5 hours in front of the computer while surfing, and trying to find a packer but nothing found.

PS: I have 40 points now, but as soon as gets over 200 points, I  am going to ask a dummy question for you BlackMan

Regards,
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 200 total points
ID: 1355886
Glad to help.

Cheers,
Phil.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

17 Experts available now in Live!

Get 1:1 Help Now