C++ Builder IDE >> Using OnActivate, OnCreate , OnDestroy, OnClose, etc.

by DKat » Thu, 28 Jul 2005 03:35:40 GMT

I was happliy using these Events in my program to do various clean up tasks
and I was told by this group (or probably Component use) NOT to do so. That
I should use MainForm and ~MainForm. Now that my head is above water and I
have some air to breathe I would like to know why as do others in my
department who still use the other means. They seemed to work just fine
where as I have to be real careful when using either of the other two that
I'm not killing or creating something before it can exist or after it should
have been deleted.




Similar Threads

1. ~mainform vs OnClose OnDestroy, - mainform vs OnCreate, OnActivate.. - Borland C++ Builder VCL Components

2. ~mainform vs OnClose OnDestroy, - mainform vs OnCreate, OnActivate..

I was happliy using the Mainform Events in my program to do various clean up 
tasks (delete and pop) and I was told by this group (or probably Component 
use) NOT to do so.  That I should use MainForm and ~MainForm.  Now that my 
head is above water and I have some air to breathe I would like to know why 
as do others in my department who still use the other means.  They seemed to 
work just fine where as I have to be real careful when using either of the 
other two that I'm not killing or creating something before it can exist or 
after it should have been deleted. 


3. ~mainform vs OnClose OnDestroy, - mainform vs OnCreate, - Borland C++ Builder VCL Components

4. WM_ENDSESSION OnClose OnDestroy...

Hi,
According to MS when WM_ENDSESSION is called WM_DESTROY an onClose are no
longer called.

Does anybody know the reason why?
Doesn't it make the whole call WM_DESTROY a bit useless?

I have some list ctrls that need to free some memory before the window is
destroyed where should I put the clean-up to ensure that it is called both
when the user close the dialog or it is closed when the user logs off?

Many thanks

Sims


5. TForm OnClose and OnDestroy (and other help needed) - Delphi/Pascal

6. OnCreate and OnDestroy of non-form object

In D4, I am creating and later destroying an object which is in a separate 
unit, and I want to create and destroy a timer component which will exist 
while the object exists. It does not have a form or any visible components. 
It is simply a set of functions and procedures which are called by the 
OnTimer event. I have done it as follows but I am not sure it is correct:


  type  TOrtUpdate = class( TObject )

  public
    UpdateTimer: TTimer;  // ExtCtrls
    constructor Create;   // (AOwner: TObject); override;
    destructor Destroy; override;
  end;

  implementation

  constructor TOrtUpdate.Create;   //(AOwner: TComponent);
  begin
    inherited Create;              //(AOwner);
    UpdateTimer := TTimer.Create(nil);
  end;

  destructor TOrtUpdate.Destroy;
  begin
    UpdateTimer.Free;
    inherited Destroy;
  end;

This differs somewhat from the help description of overriding the 
constructor, which was for a TComponent. With TObject it complained about 
overriding a static method. The code from the example is shown as comments.

Thanks,

Paul 


7. OnCreate & OnDestroy

8. question about System.String, CString, PCSTR, etc, etc

Trying to wrap an unmanaged class.
Here is the function I'm trying to wrap:
bool Init(PCSTR filename, PCSTR username, PCSTR password, PCSTR working);


In my managed C++ class, I have a method like this:
bool CSUSSWrapper::Init(String* filename, String* username, String*
password, String* working)

{

      CString _filename(filename);

      CString _username(username);

      CString _password(password);

      CString _working(working);

      return m_objSourceSafe.Init((PCSTR)_filename, (PCSTR)_username,
(PCSTR)_password, (PCSTR)_working);

}



Now that seems really ugly and probably not necessary.  It compiles and it
works, but it's UGLY.  Is there a cleaner way?

THanks,
Steve