#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    24
    Rep Power
    0

    Stack Overflow on FormCreate


    Have what I believe to be an uncomplicated VCL form. It needs to call the constructor of a used unit. I placed the constructor call in the OnCreate event of the form. Dproj file contains a single call to Application.CreateForm(...), followed by Application.Run.

    Execution gives a stack overflow error. Debug tracking reveals that the OnCreate method is called over and over, resulting (I guess) in the stack overflow.

    Can anyone explain what might be going on.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by jwcane
    Can anyone explain what might be going on.
    We would really need to see the code.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    24
    Rep Power
    0

    Program Source Link


    Originally Posted by majlumbo
    We would really need to see the code.
    Complete source archive is at http://secure.enw-ltd.com/enwSMTP.zip. Thanks.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Originally Posted by jwcane
    Complete source archive is at http://secure.enw-ltd.com/enwSMTP.zip. Thanks.
    I cannot be sure what the origin of this specific error is, however, two problems stand out. You define these two methods

    Code:
        Constructor Init;
        Destructor Free;
    A constructor is a method to create the object that that method is part of. You are creating another object within the Init method, but you are not creating the form itself (A constructor defined within the form's declaration would be to create the form). Change Constructor Init to Procedure Init.

    A Destructor is also to destroy the object that the method is part of. Your form already has a destructor. Get rid of this declaration altogether, and the object that you are freeing in this destructor can be freed in the form's OnClose event.

    Code:
    procedure TfmSendMail.FormClose(Sender: TObject);
    begin
       theMessage.Free;
    end;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0
    TApplication.CreateForm calls the form constructor Create, which triggers the OnCreate event, which calls your procedure FormCreate, which calls your constructor Init, which triggers the OnCreate event, which calls your procedure FormCreate, which calls your constructor Init...
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    24
    Rep Power
    0
    Thanks all. Found and fixed.

    Originally Posted by imak
    TApplication.CreateForm calls the form constructor Create, which triggers the OnCreate event, which calls your procedure FormCreate, which calls your constructor Init, which triggers the OnCreate event, which calls your procedure FormCreate, which calls your constructor Init...

IMN logo majestic logo threadwatch logo seochat tools logo