Solved

Reducing the Exe Size

Posted on 1999-01-11
13
298 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Use this EXE packer:
www.alenka.spb.ru/aspack/
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
Aargh, meant it as a comment, sorry!
0
 
LVL 1

Expert Comment

by:hustch
Comment Utility
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
Comment Utility

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
Comment Utility
The EXE packer which I mentioned in my com.., eh, answer, is free with no nag dialogs...
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility

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
Comment Utility
Glad to help.

Cheers,
Phil.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

7 Experts available now in Live!

Get 1:1 Help Now