How to achieve smaller size of the executable?

前端 未结 8 1344
感情败类
感情败类 2020-12-05 08:41

Very recently I have come back to Delphi after a long pause and written a rather straightforward utility app my client requested to support an older release...

I kno

相关标签:
8条回答
  • 2020-12-05 08:45

    MapFileStats (DelphiTools.info) is a good (free) tool that allows you to see how much space every unit occupies in your executable. My own tool DelphiUnitSizes is an alternative that in addition to unit sizes also display the size of each function or class.

    Delphi 2010 made the default executable about 30% larger, probably because of RTTI included in the RTL/VCL units, so you can use an older version of Delphi for smaller exe-size.

    As others have mentioned UPX is a great tool too, the false positives by virusscanners are not that frequent in my experience.

    The size of Delphi-executables can be very much trimmed down using custom System-units and UPX-compression. I can generate exe-files that are less that 64kb in size with my Delphi-based game-generator ZGameEditor, even with Delphi Berlin.

    0 讨论(0)
  • 2020-12-05 08:47
    • You can try using KOL (Key Objects Library is a set of objects to develop power (but small) 32 bit Windows GUI applications using Delphi but without VCL). KOL allows to create very compact Windows32 GUI applications (starting from ~11K without compression - if suggested system units replacement used). The most of code is converted to built-in assembler.

    • Another option is use a exe compressor like UPX.

    0 讨论(0)
  • 2020-12-05 08:52
    1. Did you do a debug or release build? (Make it release for smaller size, make sure optimization is on, debug information turned off)

    2. Did you turn off RTII (delphi 2010 and up) if not needed? (Smaller EXE sizes.)

    3. Number of units in your uses clause of your main unit, is not a good way to guess EXE size. Think of it this way: The VCL itself is one large amount of code, the Database Layer another, and the stuff you write is probably a very small percentage of the EXE size.

    4. To understand your executable size, try the JCL Project Analyzer, or read the MAP file that is produced when you turn on the Map option. This will tell you exactly what is inside your executable file.

    It would be silly for various reasons, but you could get a smaller executable by using Delphi 7, for example. In the end when I make an application and I want to make it smaller, I look at how much time it would take, and how much effort to rebuild everything (such as with a vcl alternative) and I then say to myself, forget about it.

    0 讨论(0)
  • 2020-12-05 08:59

    Yes, but then you'd need to supply the other code units as additional files. Just as .net required the assembly, and you have VB runtimes etc., this is just the Delphi runtime - but it's embedded in the exe.

    Another option is to compress the executable, there are tools for that around.

    0 讨论(0)
  • 2020-12-05 09:02

    How big is your DFM? It is included as a resource in your EXE. Depending on how complex your GUI is, you might find that creating the GUI at runtime in code could reduce the EXE size.

    0 讨论(0)
  • 2020-12-05 09:03
    • You say you're coming back to Delphi. If you still have an old version available, use that - every new version adds extra features and if you don't need them them your exes will be smaller without them.

    • Make sure you're only including units you actually use.

    But whatever you do I very much doubt you'll get down to 300k. If memory serves, even a 'hello world' application in Delphi 2 would be larger than that.

    0 讨论(0)
提交回复
热议问题