Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server chrashs
#1
Hello

I have a Server in IntraWeb, Application mode, with 9 Pages.

the ServerControllerBaseConfig looks like this:

Code:
void __fastcall TIWServerController::IWServerControllerBaseConfig(TObject *Sender)
{
  TmainForm::SetURL("/", "mainForm"); 
  TwakoForm::SetURL("/", "wakoForm"); 
  TadrForm::SetURL("/", "adrForm"); 
  TzahlForm::SetURL("/", "zahlForm"); 
  TpaypalForm::SetURL("/", "paypalForm");   
  TendeForm::SetURL("/", "endeForm"); 
  TbestellForm::SetURL("/", "bestellForm"); 
  TNexiForm::SetURL("/", "nexiForm"); 
  TnexiErrForm::SetURL("/", "nexiErrForm"); 

  RegisterContentType(L"application/json");   


  ...
}

and in mainform-create is the alloc of these pages like:


Code:
void setAsMainForm() {
  TmainForm::SetAsMainForm();
}
#pragma startup setAsMainForm


void __fastcall TmainForm::IWAppFormCreate(TObject *Sender)
{
try {
        wakoForm = new TwakoForm(this);
        adrForm  = new TadrForm(this);
        bestellForm = new TbestellForm(this);
        zahlForm = new TzahlForm(this);
        endeForm = new TendeForm(this);
        paypalForm  = new TpaypalForm(this);
        nexiForm  = new TNexiForm(this);
        nexiErrForm  = new TnexiErrForm(this);
    }
catch(Exception &ex)
    {
      CreErrTxt = "Exception creating Forms : " + ex.Message;
      isCreErr = true;
    }
...



if (isCreErr)
 throw Exception(CreErrTxt)

most times , it works.
but if an error occurs, I throw an exception to end this session.
This may happen, if something goes wrong in wakoForm->Create or other constructor calls.

If I throw a Exception like described, these Session dies and thats ok.
But now, other sessions can no longer get created. Every new one comes with an access violation when created by "new" .

I can't find out, why
I solved it by notice the exception but throwing it in onShow, instead of onCreate. Now it works.

I looked for hours to find a reason, but it seems , that an Exception in mainForm.create prevent the server from creating new sessions .

CBuider 10.2.3   IW 15.6.7




greetings from germany
  jörg
Reply
#2
Hi Jörg

This shouldn't occur at all. Something else is going on.

- Are you explicitly raising the exception inside the form's OnCreate event or it's being caused by something else?

- Can you recreate this behavior in a simple test case application using the same IW version?
Reply
#3
(03-04-2025, 09:14 AM)Alexandre Machado Wrote: Hi Jörg

This shouldn't occur at all. Something else is going on.

- Are you explicitly raising the exception inside the form's OnCreate event or it's being caused by something else?

- Can you recreate this behavior in a simple test case application using the same IW version?

Hi Alexandre

thanks for your replay
yes I raise the exception in case of some errors like I can't open a datebase or cannot read a config file or anything else.

I will make a test-app in the next week.
Reply
#4
I have a theory on this.  I think this code in the IWAppFormCreate event:

Code:
wakoForm = new TwakoForm(this);
adrForm  = new TadrForm(this);
...

is the problem as it's the C++ way but not the IW way.  IW will create these forms on demand by something like WebApplication->GoToURL("/paypalForm") if you use SetURL or WebApplication->ShowForm(__classid(TpaypalForm),false,true), etc.

If you are creating these forms ahead of time to be able to access them via the variables you created for future reference it might just be 'accidentally' working most of the time for you.

If you remove the pre-creating form code from IWAppFormCreate and access your other forms something like this:

Code:
TpaypalForm *f = dynamic_cast<TpaypalForm *>(WebApplication->FindFormByName("paypalForm"));
if(f) { f->Show(); } else { new TpaypalForm(WebApplication)->Show(); }

it may always work correctly without affecting the session.
Reply
#5
(03-05-2025, 11:54 PM)MJS@mjs.us Wrote: I have a theory on this.  I think this code in the IWAppFormCreate event:

Code:
wakoForm = new TwakoForm(this);
adrForm  = new TadrForm(this);
...

is the problem as it's the C++ way but not the IW way.  IW will create these forms on demand by something like WebApplication->GoToURL("/paypalForm") if you use SetURL or WebApplication->ShowForm(__classid(TpaypalForm),false,true), etc.

If you are creating these forms ahead of time to be able to access them via the variables you created for future reference it might just be 'accidentally' working most of the time for you.

If you remove the pre-creating form code from IWAppFormCreate and access your other forms something like this:

Code:
TpaypalForm *f = dynamic_cast<TpaypalForm *>(WebApplication->FindFormByName("paypalForm"));
if(f) { f->Show(); } else { new TpaypalForm(WebApplication)->Show(); }

it may always work correctly without affecting the session.

Thankx for your reply

Hmmm .... ok, I will try it.
But I donT have a problem to access these forms ,  the app runs . Its only , if an exception throws in createForm of main.
then the serverprocess crashs . An exception at later time. while the page is running doesn't have any effects to other sessions
Reply
#6
(03-05-2025, 11:54 PM)MJS@mjs.us Wrote: I have a theory on this.  I think this code in the IWAppFormCreate event:

Code:
wakoForm = new TwakoForm(this);
adrForm  = new TadrForm(this);
...

is the problem as it's the C++ way but not the IW way.  IW will create these forms on demand by something like WebApplication->GoToURL("/paypalForm") if you use SetURL or WebApplication->ShowForm(__classid(TpaypalForm),false,true), etc.

If you are creating these forms ahead of time to be able to access them via the variables you created for future reference it might just be 'accidentally' working most of the time for you.

If you remove the pre-creating form code from IWAppFormCreate and access your other forms something like this:

Code:
TpaypalForm *f = dynamic_cast<TpaypalForm *>(WebApplication->FindFormByName("paypalForm"));
if(f) { f->Show(); } else { new TpaypalForm(WebApplication)->Show(); }

it may always work correctly without affecting the session.


@MJS

your code does almost the same as the WebApplication->ShowForm() does

For all IntraWeb users, both Delphi and C++Builder, I strongly suggest to forget about form variables and always use the WebApplication instance. WebApplication->ActiveForms list always contains the correct reference for each form created in that session context.

BTW, ShowForm() has 2 different overloaded versions:


Code:
ShowForm(System::Classes::TComponentClass AFormClass, bool AReleaseActiveForm = false, bool AUseExistingInstance = false);

ShowForm(const System::UnicodeString AFormClassName, bool AReleaseActiveForm = false, bool AUseExistingInstance = false);

In the first version you pass the form class, in the second version you can use the form class name (but you have to register the form class using RegisterClass() function before using it). I personally like the second version because it allows you to create/show a form without the need to reference it's unit
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)