Board index » delphi » After Form Create, before Form Destroy

After Form Create, before Form Destroy

I need som help !!

I want the parent Form's onCreat to run TFormLogo.Restore and onDestroy
to run TFormLogo.Save ! How do I do this ???

My Component save/restore (Ini-file) some information (defaults) uniq
for every user.

type                          
  TFormLogo = class(TComponent)
  public
    { Public declarations }
    procedure Restore;
    procedure Save;
  end;

(Today I have to program FormCreate/FormDestroy (Restore/Save) every
time)

Helge.

 

Re:After Form Create, before Form Destroy


Helge -

Have your TFormLogo call Restore from within its Create constructor
and Save from within its Destroy destructor.

Good luck.

Kurt

Re:After Form Create, before Form Destroy


Quote
Kurt Barthelmess (TeamB) wrote:

> Have your TFormLogo call Restore from within its Create constructor
> and Save from within its Destroy destructor.

Thanks!

Calling Restore from within Create constructor was ok!

When i call Save from within Destroy all components are destroyed i'm
not able to save the information. How do I save components-information
before its destroyd ??

Helge.

Re:After Form Create, before Form Destroy


In addition to Kurt's response, note that you should only attempt to
save the individual component's information in its destructor.  You
would not want to save another component's information as you don't know
whether that component still exists.

Each component can save its own info into the same INI file without any
problems.

--
Mark Richter
eMCee Software

Re:After Form Create, before Form Destroy


Helge -

Sounds like you're either doing it in the wrong order or there's an
ownership conflict. On the first, your Create constructor needs to
call its ancestor's Create before you start doing stuff. But your
Destroy destructor needs to do its stuff before it calls the inherited
method.

On the ownership conflict - who owns the information your component is
trying to save? If not your component, then you are in serious trouble
(not to mention in gross violation of the rules of component
warfare<G>.)  There's no way to ensure that when an Owner decides to
self destruct that you can force your component to be destroyed first
(to give a shot at saving info about other components.) But the Owner
itself should still be intact. IOW, a component can look at its Owner
before the component's destruction, but it can not be assured that the
Owner's other components still exist. Of course, you can't be sure of
that even during normal run-time execution, either.

Good luck.

Kurt

Re:After Form Create, before Form Destroy


Quote
Kurt Barthelmess (TeamB) wrote:

> Sounds like you're either doing it in the wrong order or there's an
> ownership conflict. On the first, your Create constructor needs to
> call its ancestor's Create before you start doing stuff. But your
> Destroy destructor needs to do its stuff before it calls the inherited
> method.

> On the ownership conflict - who owns the information your component is
> trying to save? If not your component, then you are in serious trouble
> (not to mention in gross violation of the rules of component
> warfare<G>.)  There's no way to ensure that when an Owner decides to
> self destruct that you can force your component to be destroyed first
> (to give a shot at saving info about other components.) But the Owner
> itself should still be intact. IOW, a component can look at its Owner
> before the component's destruction, but it can not be assured that the
> Owner's other components still exist. Of course, you can't be sure of
> that even during normal run-time execution, either.

Thanks !

My Component save/restore (Ini-file) some information (defaults) uniq
for every user.

type                          
  TFormLogo = class(TComponent)
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;  
    destructor Destroy; override;
    procedure Restore;
    procedure Save;
  end;

When i use this destructor i ought to be able to save the parent form
information (propertys), but when i try to save the parent the parent
form are derstoyd (nil).

destructor TFormLogo.Destroy;
begin
     Save;
     inherited Destroy;        
end;

How can i fix this problem ??

Helge.

Re:After Form Create, before Form Destroy


Quote
Mark Richter wrote:

> In addition to Kurt's response, note that you should only attempt to
> save the individual component's information in its destructor.  You
> would not want to save another component's information as you don't know
> whether that component still exists.

> Each component can save its own info into the same INI file without any
> problems.

Thanks !

type                          
  TFormLogo = class(TComponent)
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;  
    destructor Destroy; override;
    procedure Restore;
    procedure Save;
  end;

When i use this destructor i ought to be able to save the parent form
information (propertys), but when i try to save the parent the parent
form are derstoyd (nil).

destructor TFormLogo.Destroy;
begin
     Save;
     inherited Destroy;        
end;

How can i fix this problem ??

Helge

Re:After Form Create, before Form Destroy


Helge -

 > When i use this destructor i ought to be able to save the parent form
 > information (propertys), but when i try to save the parent the parent
 > form are derstoyd (nil).

That's not possible. After all, it is your Owner that has called your
destructor, so it can not be nil or it couldn't be calling.

We may have a terminology problem here - you may need to distinguish
between a "Parent" and an "Owner". What exactly is the relationship
between your component and the form for which you are trying to save
information?

Good luck.

Kurt

Other Threads