Article View: borland.public.cppbuilder.nativeapi
Article #2730Re: Creating new TForm causes 'Out of Resources' error on WinXP
From: Remy Lebeau (TeamB)
Date: Thu, 18 Jan 2007 21:41
Date: Thu, 18 Jan 2007 21:41
70 lines
3199 bytes
3199 bytes
"Dan Mayo" <dmayo@dickey-john.com> wrote in message
news:45afd751$1@newsgroups.borland.com...
> YES There is no other way for the code to exit from that function.
What about if exceptions occur? You are not protecting your code from
that scenerio at all.
> My whole user interface has a number of other buttons, labels,
graphs,
> etc. The weird thing I don't understand is that I am basically in a
loop:
You don't need to re-create the form on each iteration of the loop.
You could create it once and then let the loop show/hide it as needed.
Try this instead:
void MyClass::TheLoop()
{
TMyForm *theDialog = new TMyForm(NULL); // no Owner needed
try
{
bool Stop = false;
while( !Stop )
{
theDialog->ProgressBar->Position = 0;
theDialog->ProgressBar->Max = ...;
theDialog->Stopped = false;
theDialog->Show();
TriggerLongHardwareRelatedTask();
bool DoingSomeLongHardwareRelatedTask = true;
while( DoingSomeLongHardwareRelatedTask && !Stop )
{
if( theDialog->ProgressBar->Position <
theDialog->ProgressBar->Max )
theDialog->ProgressBar->StepIt(); // Set the
Step property to 1
else
theDialog->ProgressBar->Position = 0;
DoingSomeLongHardwareRelatedTask =
!HardwareTaskComplete();
Application->ProcessMessages();
Stop = theDialog->Stopped;
}
theDialog->Hide();
}
}
__finally
{
delete theDialogThatCrashes;
}
}
Now, with that said, you should seriously consider moving the hardware
code into a separate worker thread instead. The thread can post
notifications about its status to the main thread to update the
dialog. It is not good to perform lengthy operations in the main
thead, and call ProcessMessages() like that can introduce other subtle
problems elsewhere.
Gambit
Technical Details
Message-ID:
<45afe953$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45afcda9$1@newsgroups.borland.com> <45afd2ea$1@newsgroups.borland.com> <45afd751$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,81568e00a202778e X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <45afcda9$1@newsgroups.borland.com> <45afd2ea$1@newsgroups.borland.com> <45afd751$1@newsgroups.borland.com> Subject: Re: Creating new TForm causes 'Out of Resources' error on WinXP Date: Thu, 18 Jan 2007 13:41:05 -0800 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.34.171 Message-ID: <45afe953$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1169156435 75.83.34.171 (18 Jan 2007 13:40:35 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail