1

Topic: To do all classes by successors from TWinControl?

All greetings!
I as you know, not especially love OOP, but on the sly it is necessary to work with it.
Here, for example, I created the class.

type TMyObject=class (TObject)
The designer there, all affairs...
end;

In one of form methods I do

Vasya = TMyObject. Create (...);

And then anywhere I do not do clearing of this object.
Also what you think?
At program termination I catch an exception that Memory Leak!
Then, I do so

type TMyObject=class (TWinControl)

And at creation of object I specify that the owner of this object - one of "forms" of my application.
And  - any memory leak, even thus that anywhere in the program I do not release this object.
Then the form itself cares of clearing of storage of all child objects?
Then why all created classes not to do by successors from TWinControl?
Time the form so well is able to care about the wines-control of wards.

2

Re: To do all classes by successors from TWinControl?

And then thousand such objects  that, and without living till the end of application operation to take off with an error out of memory :-)

3

Re: To do all classes by successors from TWinControl?

OOP. wrote:

then why all created classes not to do by successors from TWinControl?
Time the form so well is able to care about the wines-control of wards.

Because everyone TWinControl has a window, and their amount is restricted.
Because the form cares only of the Child instead of about whom got.
TComponent use, at it is Owner which too cares of destruction of the Slave.

4

Re: To do all classes by successors from TWinControl?

Dimitry Sibiryakov wrote:

TComponent use

Yes, I too tried it - works.
Then why many are created by classes-successors from TObject?
Why at once not to inherit from TComponent?
Inconveniences - any, advantage - is available.

5

Re: To do all classes by successors from TWinControl?

The beginner of OOP.;
Yes, the form cares about  all sons. It, however, does not rescue from memory leaks if you create some the objects successively with the same name. Then it will be released only last of the created. Well and waste of resources - all the same everyone WinControl is a separate window with message queue.

6

Re: To do all classes by successors from TWinControl?

OOP. wrote:

inconveniences - any

Yes, short of brakes just on creation and removal because of registration at the owner.
You do not check, but some programmers care of high-speed performance of the .

7

Re: To do all classes by successors from TWinControl?

OOP. wrote:

then why many are created by classes-successors from TObject?

Many it who? SURNAMES, appearances, passwords!!!

8

Re: To do all classes by successors from TWinControl?

Victor Cookin wrote:

the Beginner of OOP.;
Yes, the form cares about  all sons. It, however, does not rescue from memory leaks if you create some the objects successively with the same name. Then it will be released only last of the created...

9

Re: To do all classes by successors from TWinControl?

...Surrenders to me, the beginner wants  ARC and TInterfacedObject:-D

10

Re: To do all classes by successors from TWinControl?

OOP. wrote:

...
Here, for example, I created the class.

type TMyObject=class (TObject)
The designer there, all affairs...
end;

In one of form methods I do

Vasya = TMyObject. Create (...);

And then anywhere I do not do clearing of this object.
...

In books on programming on Delphi it is recommended to do clearing. Try to follow to this council, it is much easier, than for nothing to spend resources, being inherited from TWinControl or even TComponent.

11

Re: To do all classes by successors from TWinControl?

schi wrote:

In books on programming on Delphi it is recommended to do clearing.

it is difficult to disagree With this obvious statement.
And all began that to me the thought came to a head - and that if my application is completed by a supernumerary method (well for example to it make kill of the Manager of Tasks) then the code which releases objects business simply does not reach - here and leak turns out.

12

Re: To do all classes by successors from TWinControl?

OOP. wrote:

for example to it make kill of the Manager of Tasks

....Then the operating system simply destroys all storage of your program together with all objects-shmabektami and that there in that storage during that moment will be

OOP. wrote:

the code which releases objects business simply does not reach

Truly
And here exactly in the same way does not reach the code releasing your components-owners or forms-owners, and  and they in turn will not release your artful objects-with-owners

13

Re: To do all classes by successors from TWinControl?

OOP. wrote:

to me the thought came to a head

Then you should read Richter and generally books about design of the modern operating systems
While this thought does not leave, putting the tail between the legs.

14

Re: To do all classes by successors from TWinControl?

OOP. wrote:

it is passed...
It is difficult to disagree with this obvious statement.
And all began that to me the thought came to a head - and that if my application is completed by a supernumerary method (well for example to it make kill of the Manager of Tasks) then the code which releases objects business simply does not reach - here and leak turns out.

Well, at first, no leak will exist: OS cleans all.
And secondly, memory leak is not when forgot to clean objects on termination of application. Though it too is important, but it - not memory leak.
Leak is an uncontrolled capture of resources (operative storage, for example).
For example, you can create every time objects with  Owner, and at application end, at destruction Owner all "by itself" as though resolves. Well also what? Application at uncontrolled creation (without explicit clearing) objects can simply not live till the moment "" end. To you it will be easier, what application falls because of shortage of storage, but thus you will know, what if it did not fall - that all objects would be released?