Close / Destruct problem

I have a dynamically created web container within another container. I do have a Method called “SAVE” that stores the values of text fields to database. Method works as expected when called. Actually everything was working but then I tried to implement “Autosave” idea…
Two things came to mind:

  1. Use the Destructor (and call SAVE inside destructor); Or
  2. Use the Close event ( call SAVE here).

Currently the code is:
MyContainer.Close
MyContainer = nil

When using the destructor, It “destructs” the values in text fields, thus saving NULL to database. Probably because “Close” is above. But it can’t be bellow, because it will be nil, thus unable to close. So I cant call “Save method” in destructor, because it will not save current values but nulls.

When using the “close” event, everything is as expected (values are into database) but the container remains open!

Basically the question is - is there a way to call Close, do stuff, but also do close the container?
I would also appreciate any idea that might implement autosave upon dynamically created container being closed or destructed.

What about calling the destructor at the end of close ?

Why Not call save method first manually?

Weird. Do you interact with the interface during this process or just do fast background tasks and end?

[quote=110685:@Metodija Angjelkoski]wo things came to mind:

Use the Destructor (and call SAVE inside destructor); Or
Use the Close event ( call SAVE here).
Currently the code is:
MyContainer.Close
MyContainer = nil

When using the destructor, It “destructs” the values in text fields, thus saving NULL to database. Probably because “Close” is above. But it can’t be bellow, because it will be nil, thus unable to close. So I cant call “Save method” in destructor, because it will not save current values but nulls.

When using the “close” event, everything is as expected (values are into database) but the container remains open!

Basically the question is - is there a way to call Close, do stuff, but also do close the container?[/quote]

Actually, the real question is : why don’t you call your save method BEFORE calling MyContainer.Close ? Why insist on placing save in the Close event or the Destructor ?

If you really want to automate all containers close, create a method that takes a container as argument, where you first save, and then call container.close. For instance MyClose(CCtoClose as WebContainer).

Michael, Christian, I am calling close() from master container, so save does not exist there. MyContainer is a property of the master with Super: WebContainer. It may hold any container. So in master I can use stuff line “Close”, “Constructor” and so on, but not a method that is in the sub container.
If I Use Nil then Close - I have nil object exception (Can’t close nil)

The Idea with MyClose, might work. need to try.