Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

How should I free a dock panel containing a form.

I am creating a new instance of an editor form and placing the form on a tabbed dock panel.  I have added an event handler (DoClose) for the dock panel which is placed in the editor form and I use to determine if document needs saving etc.  I finish the handler with Action := caFree. 
If I click on the Close X on the DocPanels header, my OnClose event handler in my Editor Form is called, see below:

procedure TfmEditor.DoClose(Sender: TObject; var Action: TLMDockPanelCloseAction);
begin
// do my preclosing work here...
fmEditor.Close;
Action := caFree;
end;

When I try and open another document I get an access violation.  Something isn't being cleared properly

Removing caFree works and I can open other tabbed tabbed documents but tabs for all documents opened remain even though the forms placed on them have now been closed.

How should I be closing my documents to stop this happening?


Tagged:

Comments

  • 9 Comments sorted by Votes Date Added
  • Most probably, your form is destroyed along with its parent dock-panel, and you wrongly trying to re-use same (destroyed) form instance in the second editor document. To answer more precisely, I need to look at the code in which you creates editor document.
  • I have attached an extract the code which creates the Docked editor.
    I hope that is sufficient, but I have also included  some editor code.
    txt
    txt
    Extract of Panel Create Code.txt
    2K
    txt
    txt
    editor form create, doenter, doclose and destroy code.txt
    2K
  • Don't know what to say you, your code is complicated and use a lot of other stuff. The demo of DockingPack works ok, so I think the issue is somewhere in your code. 
    If you can isolate the issue, by removing everything from your project except docking site itslef, empty TfmEditor form and doc creation/closing logic, I can look (please, send demo project to our support e-mail).
  • OK, I'll try and produce a much reduced demo project.
  • Just tried to get the Demo project up and running so I could build a simple project based on that, however, I cannot compile it as it is trying to load the Rad Studio Style files from the wrong location.  With Rad Studio 10.3.2 these files are in a different place:

    C:\users\public\embarcadero\studio\20.0\styles\.  

    I created the location that the vrc file is expecting but there are still discrepancies between the file naming in the vcr and the files in the 10.3.2 installation.

    I don't have a res file editor so can you suggest I resolve this.
  • Try to open project's settings, and check/uncheck some VCL Styles. Usually this helps.
  • This is a modified version of the Docking Demo.  I haven't been able to reproduce the same Access violation when opening a doc after a doc has been closed but I am getting an access violation when I close the application with documents open or when I try to close more that one document. 

    Can you suggest a solution?
    zip
    zip
    lmddocking.zip
    2M
  • I see no bugs in our code. Several things for you to consider:

    1) If I remove ShowMessage from TfmEditor.FormDestroy method, no exception is raised. ShowMessage raises exception probably because it needs a handle of main form, but the handle is already destroyed at the moment. So, do not show messages in FormDestroy.

    2) MyStrList.Free should be placed in FormDestroy, not in TfmEditor.DocClose. And, of course, MyStrList should not be a global variable.

    3) Since you create several instances of TfmEditor during application lifecicle, its better to remove fmEditor: TfmEditor global variable. And exclude fmEditor from auto-created form list in porject's options.
  • Thanks for suggestions, I was expecting error in your code, it was just my understanding using Docking.. First application I have tried to develop using docking. 

    I had actually implemented most of what you suggested but I was trying to cut things down to a minimum based on your demo code.  I was a useful learning process for me and thank you for your patience.  It requires a rather different mindset from Tab Page Controls and tab sets.
Sign In or Register to comment.