Board index » cppbuilder » Processing during form creation?

Processing during form creation?

Hi,

This is probably a newbie question, but it is quite a problem for me:

I am making an application with several dialogs that I show modally. One
of these need to do some processing, either before, during or just after
it is shown (modally). Depending on the result of this processing, I
will either need to modify some of the dialog components or close the
dialog, showing instead a message stating that the processing failed.

I have great difficulty getting this to work. It seems that all the
available events (OnCreate, OnActivate, OnShow) as well as the form
constructor itself are executed at a time when it is either not allowed
to modify the components or it is not allowed to close the form
(probably due to it being shown modally and/or because the form is not
finished showing itself).

Can anyone tell me if (and how) this can be done, or if I will have to
move all processing out of the dialog and place it in my main thread
instead (and thus showing the dialog non-modally)?

So far, the only solution I've found to work, is having a timer wait a
little while (for the form creation to complete) and then start the
processing. This is not really satisfactory, since the user might start
manipulating the components on the form before the processing has been
done. Also it is the dirtiest way I can imagine doing this simple task.

Any help or info is welcome!

Regards,

Adam.

 

Re:Processing during form creation?


One way to do that whould be to construct the form first, then do the
processing before showing it:

    TMyForm *form = new TMyForm(this);
    form->DoSomething();

    if(some_condition)
        form->ShowModal();
    else
        ShowMessage("failed");

    delete form;

Gambit

Quote
"Adam Nellemann" <a...@nellemann.nu> wrote in message

news:3c8c1173$1_1@dnews...
Quote
> I am making an application with several dialogs that I show modally. One
> of these need to do some processing, either before, during or just after
> it is shown (modally). Depending on the result of this processing, I
> will either need to modify some of the dialog components or close the
> dialog, showing instead a message stating that the processing failed.

Re:Processing during form creation?


Thanks Gambit!

Got it working myself, but I actually think I'm doing something much
like you suggest. I still think it is strange that Borland doesn't
provide an event that occurs after all the internal stuff has been
done?!?

Adam.

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote in message
news:3c8c2a63$1_2@dnews...

Quote
> One way to do that whould be to construct the form first, then do the
> processing before showing it:

>     TMyForm *form = new TMyForm(this);
>     form->DoSomething();

>     if(some_condition)
>         form->ShowModal();
>     else
>         ShowMessage("failed");

>     delete form;

> Gambit

> "Adam Nellemann" <a...@nellemann.nu> wrote in message
> news:3c8c1173$1_1@dnews...

> > I am making an application with several dialogs that I show modally.
One
> > of these need to do some processing, either before, during or just
after
> > it is shown (modally). Depending on the result of this processing, I
> > will either need to modify some of the dialog components or close
the
> > dialog, showing instead a message stating that the processing
failed.

Re:Processing during form creation?


You could try overriding the inherited AfterConstruction() method.

Gambit

Quote
"Adam Nellemann" <a...@nellemann.nu> wrote in message

news:3c939edc$1_2@dnews...
Quote
> Got it working myself, but I actually think I'm doing something much
> like you suggest. I still think it is strange that Borland doesn't
> provide an event that occurs after all the internal stuff has been
> done?!?

Re:Processing during form creation?


Ah, now that was a good idea! I'll keep it in mind for future projects.
(since my current problem has been solved by another workaround, like
the one you suggested earlier).

Adam.

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote in message
news:3c93b034$1_2@dnews...

Quote
> You could try overriding the inherited AfterConstruction() method.

> Gambit

> "Adam Nellemann" <a...@nellemann.nu> wrote in message
> news:3c939edc$1_2@dnews...

> > Got it working myself, but I actually think I'm doing something much
> > like you suggest. I still think it is strange that Borland doesn't
> > provide an event that occurs after all the internal stuff has been
> > done?!?

Re:Processing during form creation?


I've tried this in my current project (the OpenGL component you know
from my other posts), but it still seems that AfterConstruction is a bit
too early for what I need :(

The problem is that my OpenGL initialization has to take place AFTER a
windows handle has been created. So far I have been unable to find a
method or event that occurs only after a handle has been made (or at
least at a point in time where it is safe to have one made).

Closest I can get is to use WMPaint, which is dirty (and I'm not sure it
always works).

Adam.

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote in message
news:3c93b034$1_2@dnews...

Quote
> You could try overriding the inherited AfterConstruction() method.

> Gambit

> "Adam Nellemann" <a...@nellemann.nu> wrote in message
> news:3c939edc$1_2@dnews...

> > Got it working myself, but I actually think I'm doing something much
> > like you suggest. I still think it is strange that Borland doesn't
> > provide an event that occurs after all the internal stuff has been
> > done?!?

Re:Processing during form creation?


If the component is TWinControl-based, then you can try overriding the
inherited CreateWindowHandle() method:

    void __fastcall TMyComp::CreateWindowHandle(const TCreateParams &Params)
    {
        // call the base class first so the handle gets created
        // before you do anything with it
        BaseClass::CreateWindowHandle(Params);

        // use the newly-recreated Handle as needed
    }

Gambit

Quote
"Adam Nellemann" <a...@nellemann.nu> wrote in message

news:3ca0bdfb$1_2@dnews...
Quote
> The problem is that my OpenGL initialization has to take place
> AFTER a windows handle has been created. So far I have been
> unable to find a method or event that occurs only after a handle
> has been made (or at least at a point in time where it is safe to
> have one made).

Other Threads