Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many components can you savely have on a form ??? 1

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
I was wondering, since my application is really getting
somewhere now (it actually looks like I'm doing a decent
job here hahaha), is there a limit to the number of
components you can have on a single form ??? I have 225
individual components on my form, and it's going to be
above 300 when the is new section is finished. Although
these components never show all at the same time (imagine
that hahaha the chaos !!!), I am concerned with memory usage
and that sort of thing, or is this just peanuts for
Delphi ???

I hope you can tell me what to do,
[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hello,

I heard, but can not confirm taht the max number of controls!!! on a form can be 250, and that it is a Windows limit. Maybe we should search MSDN for this?
Don't want to start any rumours tough ;-)

HTH, TonHu
 
How come you have so many ? Are you using a PageControl ?

If so, it may be best to dynamically create the tab sheets you need and overlay appropriate forms on top. That's what I did with my app.

Create individual forms for each tab sheet then at runtime, set the parent of the form as the tab sheet and form.align := alclient.

lou
[penguin]
 
Yes weez I am using two PageControl's. I'm now just starting
to add the second pagecontrol and the extra components.

The reason why I have so many components is because I need
a whole lot of confirmations which also need data input. So
I decided that checkbox's and edits/comboboxes are the way
to go. But this has resulted in a very many controls. But as
I said before, not very many show at the same time, say
approx. 30-40 max.

I'll try to search MSDN to see if your "not-started rumor"
is true or not, TonHu :)

Thank you for your quick responses guys, [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hey weez,

I got a question regarding your solution:

What I got so far is that I took out all the components
on the second page control and placed them on seperate
forms. So what I gather from what you tell me this is what
I should do (please check out my code sample):

{TSx = TabSheet number x}

Form2.Parent := Form1.PageControl2.TS1;
Form2.Align := alClient;
Form3.Parent := Form1.PageControl2.TS2;
Form3.Align := alClient;
Form4.Parent := Form1.PageControl2.TS3;
Form4.Align := alClient;
Form5.Parent := Form1.PageControl2.TS4;
Form5.Align := alClient;
Form6.Parent := Form1.PageControl2.TS5;
Form6.Align := alClient;

That is the basic idea (I'm not at my D5 computer right now)
??? Only thing is, when I make a form a child on another
form doesnt the form end up in the memory of the first form? [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hi guys,

I also asked this very same question in the VB forum (I know, I know), and I got this reply, I thought I post it
here because it is generally usefull:


The maximum number of controls allowed on a single form depends on the type of controls used and available system resources. However, there is a fixed limit of 254 control names per form. A control array counts only once toward this limit because all the controls in the array share a single control name.

The limit on control array indexes is 0 to 32,767 on all versions.

If you layer controls on top of each other, such as using several frame controls within other frames, Visual Basic will generally accept no more than 25 levels of nested controls.

Each nongraphical control (all the controls except shape, line, image, and label) uses a window. Each window uses system resources, limiting the total number of windows that can exist at one time. The exact limit depends on the available system resources and the type of controls used.

To reduce consumption of system resources, use the shape, line, label, and image controls instead of picture box controls to create or display graphics.

Some limitations on Visual Basic, and the applications you create with it, are imposed by Microsoft Windows. These limitations may change when you install a different version of Microsoft Windows

Every open window uses some system resources (data areas used by Microsoft Windows). If you run out of system resources, the run-time error "Windows is running low on available resources" occurs. You can check the percentage of system resources remaining by choosing About in the Windows Explorer Help menu in Windows 95/98 and Windows NT 4.0 or later. Applications can also call the Windows API GetFreeSystemResources to reclaim system resources, close windows (such as open forms and Code windows, as well as windows in other applications), and exit running applications.

A single project can contain up to 32,000 "identifiers" (any nonreserved keyword), which include, but are not limited to, forms, controls, modules, variables, constants, procedures, functions, and objects. Note that the actual number of identifiers is limited to available memory.

Variable names in Visual Basic can be no longer than 255 characters, and the names of forms, controls, modules, and classes cannot be longer than 40 characters. Visual Basic imposes no limit on the actual number of distinct objects in a project. [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
BobbaFet,

Thanks for finding this information, I can use it to point a finger at someone now. The rumor I misspelled before comes from being non-english I guess.

See ya,
en de ballen (oid) :-D

Grtz, TonHu
 
aha een nederlander !!! :) ga maar ff lekker wijzen met je
vinger ;-) [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hey BobbaFet,

The 255 controls is a limit of VB, not of Delphi, I believe. It's been a while since I've used VB, but as I recall every control in VB uses a window handle, which really adds up as far as resources are concerned.

In contrast, not every Delphi control uses a window handle (if it can't receive focus, it doesn't need one -- static text, for example). So depending on the types of controls you place on your Delphi form, you will typically use fewer resources than with the equivalent VB form.

Delphi doesn't care whether a control is showing on your form or not -- if it's part of the form, it's created when the form is created, regardless of its visibility. So, the resources will be used as long as the form exists. This is also true, by the way, even if the form as a whole is not visible -- if the form exists in memory, the resources are being used.

You might be fine with about 300 controls on the form -- I'd be a bit concerned about performance (how long it takes to display/create and hide/destroy the form) but if that works out, your approach is probably the easiest to use. If performance does turn out to be a problem, I'd recommend going to dynamic control creation as suggested previously.

Good luck!

-- David
 
Icarus -- Delphi controls descended from TWinControl (which is most things) have a Window handle. So they probably count towards the limit as detailed by Bobba. Some things, like TLabel, are descended from TGraphicControl, and thus don't count towards this limit.

Bobba, take a look at how much GDI memory loading your app consumes. In Win9x, go Start | Programs | Accessories | System Tools | Resource Meter (or use the more macho memory monitor tool of your choice). Note the amount of GDI memory available. Start your app, and note how much this drops. This shows you how close to the wind you are sailing. GDI memory cannot be paged out to the swap file, so it's a finite resource. Don't launch your app from inside Delphi when you do this test, as having the form loaded in the Delphi IDE eats this same amount of memory, too.

I saw a programmer once who didn't know about creating forms at run-time; his app had 30 or so forms with 100 or so controls each; all on the Auto-create list. Launching his program, or launching Delphi and opening a few of the forms, would cause Windows to behave badly: refuse to launch other apps, freeze, etc. So that's the potential badness you're looking at; but provided you always have a good-sized chunk of GDI memory left, you should be fine.

Of course, there's also the user interface angle -- if your user is having to wade through 300 controls, is there maybe a better way to do it? -- Doug Burbidge mailto:doug@ultrazone.com
 
Hi Ronin I did what you said, and it dropped only 4%. Guess
I did something right if it drops only that much :) I'll
test again when I have more sections finished. I'll post the
results here if you guys are interrested :)

Thanx for the posts, [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Ok what I have done now, is that I have added an extra form
to my project and I have added several panels to it. I made
a procedure that makes a panel visible and the rest
invisible when a tabsheet (by detecting the parent name) of
the pagecontrol is shown by using the onShow event. Then I
set the visible tabsheet as the parent of the form with the
appropriate panel being visible of course. I think this
helps because now I can free the form when the pagecontrol
(which holds those tabsheets) is not being shown and create
the form when the pagecontrol is created. I checked it out
and it does save resources.

I do like this solution (thanx to weez). Do you guys have
an other solutions, or is this the best one ??? [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top