[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

Reducing the Exe Size

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
kyl011199
Asked:
kyl011199
  • 3
  • 2
  • 2
  • +5
1 Solution
 
philipleighsCommented:
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
 
rwilson032697Commented:
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
 
dejohn99Commented:
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
MadshiCommented:
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
 
kogerCommented:
I think I've heard of a program called sapper or zapper, which could reduce the filesize with 60%
0
 
BlackManCommented:
Use this EXE packer:
www.alenka.spb.ru/aspack/
0
 
BlackManCommented:
Aargh, meant it as a comment, sorry!
0
 
hustchCommented:
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
 
kyl011199Author Commented:

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
 
BlackManCommented:
The EXE packer which I mentioned in my com.., eh, answer, is free with no nag dialogs...
0
 
MadshiCommented:
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
 
kyl011199Author Commented:

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
 
philipleighsCommented:
Glad to help.

Cheers,
Phil.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now