Board index » delphi » Error when closing active document main form.

Error when closing active document main form.

I have followed the sample code by Steve Teixeira and  Alexandre Rai on how
to create a Active Document.  I did not hide the main form because I am just
writing a simple Active Document without the complexities of menu and
toolbar merges etc.   However, whenever I try to close the form I keep
getting "Access Violation Error".  Can anyone tell me what I am doing wrong?

{ TDelphiAxDoc }

destructor TDelphiAxDoc.Destroy;
begin
  inherited Destroy;
  FSubItem.Free;
  FItem.Free;
end;

procedure TDelphiAxDoc.DoMenuClick(Sender: TObject);
begin
  with TColorDialog.Create(nil) do
  begin
    if Execute then (Control as TMemo).Color := Color;
    Free;
  end;
end;

procedure TDelphiAxDoc.Initialize;
begin
  inherited Initialize;
  FItem := NewItem('&Change color', 0, False, True, DoMenuClick, 0,
'ColorItem');
  FSubItem := NewSubMenu('&Edit', 0, 'EditItem', [FItem]);
  Menu := NewMenu(Control, 'MainMenu', [FSubItem]);
end;

procedure TDelphiAxDoc.LoadFromStream(const Stream: IStream);
var
  OS: TOleStream;
begin
  OS := TOleStream.Create(Stream);
  try
    (Control as TMemo).Lines.SaveToStream(OS);
  finally
    OS.Free;
  end;
end;

procedure TDelphiAxDoc.SaveToStream(const Stream: IStream);
var
  OS: TOleStream;
  Memo: TMemo;
begin
  OS := TOleStream.Create(Stream);
  try
    Memo := Control as TMemo;
    Memo.Lines.LoadFromStream(OS);
    Memo.Modified := False;
  finally
    OS.Free;
  end;
end;

{ TDelphiAxDoc.IPersistStreamInit }

function TDelphiAxDoc.IsDirty: HResult;
begin
  if (Control as TMemo).Modified then Result := S_OK
  else Result := S_FALSE;
end;

initialization
  TActiveXDocumentFactory.Create(ComServer, TDelphiAxDoc, TMemo,
    Class_DelphiAxDoc, 0, 131473, tmApartment, '', 8
{DOCMISC_NOFILESUPPORT});

 

Re:Error when closing active document main form.


<<Joel Jn-Francois:
However, whenever I try to close the form I keep
getting "Access Violation Error".  Can anyone tell me what
I am doing wrong?

Quote

Have you stepped through your Destroy method? It seems the
most likely problem area. (And you've still got the call to
inherited in the wrong place.)

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error when closing active document main form.


Quote
> Have you stepped through your Destroy method? It seems the
> most likely problem area. (And you've still got the call to
> inherited in the wrong place.)

When I change the inherited position for the Destroy it makes things worse..
I can't even delete the object manually from the OLE Container if  inherited
is not called first.  This is how it is in  Steve Teixeira example to begin
with.

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.00001c4c.01a18be7@blueyonder.co.not-this-bit.uk...

Quote
> <<Joel Jn-Francois:
> However, whenever I try to close the form I keep
> getting "Access Violation Error".  Can anyone tell me what
> I am doing wrong?

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   TeamB don't see posts sent via Google or ISPs
>   Use the real Borland server: newsgroups.borland.com
>   http://www.borland.com/newsgroups/genl_faqs.html

Re:Error when closing active document main form.


<<Joel Jn-Francois:
When I change the inherited position for the Destroy it
makes things worse..

Quote

Have you stepped through your Destroy method?

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error when closing active document main form.


Quote
> Have you stepped through your Destroy method?

Yes, but I can only step through it when I am running it in Delphi without
the /regserver parameter.  And the form closes find there.. I have no
problems running it standalone from Delphi.  However, when I execute it from
the OleContainer and I try to close the form that is where I get the access
violation error.  I don't know how to step through my code at that point.

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.00001c4f.017ab21e@blueyonder.co.not-this-bit.uk...

Quote
> <<Joel Jn-Francois:
> When I change the inherited position for the Destroy it
> makes things worse..

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   TeamB don't see posts sent via Google or ISPs
>   Use the real Borland server: newsgroups.borland.com
>   http://www.borland.com/newsgroups/genl_faqs.html

Re:Error when closing active document main form.


"Joel Jn-Francois" <j...@caribtrade.com> wrote in
news:3e8c9697$1@newsgroups.borland.com:

Quote
> I have no problems running it standalone from Delphi.
> However, when I execute it from the OleContainer and I try to
> close the form that is where I get the access violation error.  I
> don't know how to step through my code at that point.

Have you tried using "Attach to process" under the Run menu?  I have
found (in D5 at least) some additional tinkering is required to get
this to work.  After attaching, press Ctrl-Alt-M to bring up the
modules window.  You should see your module in there.  Select and
right-click it and choose "reload symbols" or similar.  Browse to the
location of the DLL in your project folder.  This seems to then get
the IDE to match up to the running module propertly.  You can then add
breakpoints etc.  This works with VB so it should work with anything!

Other Threads