Exe size question


If I compile the code bellow and I'll get a 376KB in Delphi 5.
The strange is if I remove the line: data:= TDataSource.Create(nil);
I'll have 288KB. Just because of one instruction?
Is this normal? If yes, can you explain me why?

program Project1;
uses Db;
var data:TDataSource;

  data:= TDataSource.Create(nil);
  writeln('Hello World');
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The instant you use a function or method from Db the compiler really links in code from DB.
Declaring only a variable has no effect. An object variable is only a pointer.
You are lucky here. Some units drag in a megabyte.
The VCL is very much interlinked so using almost any method from any object drags in most of the VCL code.
Mohammed NasmanSoftware DeveloperCommented:
I think Delphi will not include the DB unit when you remove the line, because it doesn't require for any operation, but when you add it, it will include the DB unit, which it's big unit so it's increase the size of the exe file
lfgmartinsAuthor Commented:
OK Robert.
I agree and understand your explanation.
But how is the process. See this example:
The original size is 30 KB.
The Db include takes 250KB. = 280KB
The variable declare takes nothing more.
So why the instruction: data:= TDataSource.Create(nil);
Adds more 100KB. = 380KB
When we use the Db unit it doesn't include everything? If it included, then the size shouldn't increase when we run that instruction? Or should?
There's got to be a way to round this size increase problem? Whatelse we should all have to create our Db unit and so on...

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

I forgot.
The parameter nil. That drags in TComponent.
Code size also comes from intialization sections and resources.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

In Delphi 5 db unit uses Windows, SysUtils, Classes and Graphics units also. Perhaps that is the reason.

Regards, Geo
Hi Luis,

> The original size is 30 KB.
> The Db include takes 250KB. = 280KB
I'm just curious. Where do these numbers come from?

If I remember good, the schema is:

Using TComponent as base class, throws in 300Kb( visual VCL ).
Using TObject as base class throws in 100Kb( class management ).

Using any class throws in:

- Class's size
- Inherited class's size
- All class sizes of compound classes. When they're shared they count for 1 in size. Example: if you use 300 TEdit,
  then it fits in the 300Kb for the Visual VCL. If you use a custom class, it throws in its size.


lfgmartinsAuthor Commented:

J42, this is the size of my code in Delphi 5. It's just for you to have an idea.
DeerBear, the TObject don't occupy much because it's declared in the System unit that's automaticlly included in all projects, right?
Thanks to all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.