Howdy, Stranger!

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

In this Discussion

How do I access a Tabbed Document programatically.

I create my documents at run time and Dock them as tabbed documents.  These documents are in themselves forms which contain an editor.  How can I access these forms at run time as I don't know which is the active form.  E.g. If I close a Tab I want to Close the underlying form but I can't see how I can get access to it?
I also want to run code on entering or exiting the docked form but I cannot tell which form I am entering or exiting.
This must be pretty standard stuff so I am clearly missing something basic understanding here.  I would have expected to be able to access each form by Index but there is no index property on the Site control as far as I can see.


  • 2 Comments sorted by Votes Date Added
  • edited October 2019 Posts: 0 Accepted Answer Vote Up0Vote Down

    As shown in our demo (in TfrmMain.CreateTextDoc method), when you create new tabbed document, you create a dock panel for it. Any appropriate event handler can be assigned to created panel's OnClose event. This can be a method of your document form, for example.

    Also, if you specify caFree as a CloseAction in dock panel OnClose event handler, then the panel will be destroyed, and its child document form will also be destroyed, so, you can close your document in its OnDestroy document form event handler.

    Also, OnClose event, like most other events provides Sender parameter which will point to dock panel object. You can cast it to TLMDDockPanel type and iterate its children via VCL's standard Controls and ControlCount properties. Panel in your case will most probably have only one child, which will be your document form (use "is" operator for testing children types).

    Another possibility is to maintain some global list of dock panels and their associated document forms, since you explicitly create a dock panel for each document. And, having Sender event parameter, which refer to dock panel, search the list for corresponding document form.
  • Thanks I have been creating documents as per your demo, I was missing the child controls of the dock panel. 

Sign In or Register to comment.