> Mr. X wrote:
> > Ok,
> > Here is the sample code (below)
> > The TPanel has a button, radioButton, listbox and image parented to
> > it. Everything is been made at designTime.
> > Once the form contents are saved, cleared and the form is clicked the
> > contents reload perfectly.
> > After the reload from the memorystream, clicking the "ClearButton"
> > raises this exception :
> > Project Project2.exe raised exception class EAccessViolation with
> > message 'Access violation at address 00403714 in module
> > 'project2.exe'. Read of address 00D88000. ........
> Which is a completely different error from what you told us in the
> last message of this thread mentioning an error.
> > So my question now is :
> > 1) once the controls are got from the memory stream, what are the
> > ownership issues like ?
> > 2) Will the controls preserve their links to assigned events etc ?
> > Regards
> > X
> > ----------------------------------------------------------------------
> > ------ ----------------------------------------
> > unit Unit1;
> > interface
> > uses
> > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
> > Forms, Dialogs, StdCtrls, ExtCtrls, jpeg;
> > type
> > TForm1 = class(TForm)
> > Panel1: TPanel;
> > Button1: TButton;
> > RadioButton1: TRadioButton;
> > ListBox1: TListBox;
> > SaveButton: TButton;
> > ClearButton: TButton;
> > LoadButton: TButton;
> > Image1: TImage;
> > procedure FormCreate(Sender: TObject);
> > procedure FormDestroy(Sender: TObject);
> > procedure SaveButtonClick(Sender: TObject);
> > procedure ClearButtonClick(Sender: TObject);
> > procedure FormClick(Sender: TObject);
> > private
> > FMemStream: TMemoryStream;
> > public
> > { Public declarations }
> > end;
> > var
> > Form1: TForm1;
> > implementation
> > {$R *.dfm}
> > procedure TForm1.FormCreate(Sender: TObject);
> > begin
> > FMemStream := TmemoryStream.Create;
> > end;
> > procedure TForm1.FormDestroy(Sender: TObject);
> > begin
> > FMemStream.Free;
> > end;
> > procedure TForm1.SaveButtonClick(Sender: TObject);
> > begin
> > FMemStream.WriteComponent(Form1);
> > end;
> > procedure TForm1.ClearButtonClick(Sender: TObject);
> > begin
> > Panel1.Free;
> > savebutton.Free;
> > loadbutton.Free;
> > clearbutton.Free;
> > end;
> Here you are sawing off the branch you are sitting on. The consequences
> are, not unexpectedly, rather painful <g>.
> You cannot destroy a component from an event handler of that component,
> which you are doing here since the method is the handler for the
> ClearButtons OnClick event. After the code flow exits the method it
> will try to access things in the now dead button, that is the cause of
> your access violations.
> The typical solution to this problem is to have the event handler post
> (via PostMessage) a custom message to the form. The messages handler
> can then destroy the component safely.
> --
> Peter Below (TeamB)
> Don't be a vampire (http://slash7.com/pages/vampires),
> use the newsgroup archives :
> http://www.tamaracka.com/search.htm
> http://groups.google.com
> http://www.prolix.be