VCL Frames inserted into TRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
Posts: 2
Joined: Wed Nov 27, 2019 10:14 pm

VCL Frames inserted into TRichViewEdit

Post by Lex » Wed Nov 27, 2019 10:42 pm


I am attempting to use the functionality of inserting Delphi controls into the TRichViewEdit, however, I'm running into a slight issue. I can insert/add the controls fine but they do not copy&paste. If I'm correct I need to use RegisterClasses() and register all the required classes to make this work, which I believe I am doing.

Unfortunately, it's still not working. The control I'm inserting is my own inherited TFrame which contains various standard controls (TPanel) and DevExpress controls (TcxComboBox, TcxImage, TcxPopupEdit). When the frame is an empty TFrame containing no controls it copies & pastes just fine throughout the editor, however, as soon as I add any control (even basic controls such as TLabel, TButton, ...) this functionality stops working.

If I create my own control inheriting directly from TWinControl the copy&paste functionality works fine (even for the DevExpress controls), so I guess my question is why doesn't this work for my TFrame inherited control? Any suggestions or thoughts would be much appreciated as I'd really like to be able to use TFrame for this.

Thanks, :D .

Sergey Tkachenko
Site Admin
Posts: 14755
Joined: Sat Aug 27, 2005 10:28 am

Re: VCL Frames inserted into TRichViewEdit

Post by Sergey Tkachenko » Tue Dec 03, 2019 6:27 pm

By default, when TRichView stores a control to RVF file, it also stores all its owned components.
It is useful if you create a component that owns other components, for example:

Code: Select all

  Panel := TPanel.Create(nil);
  Button := TButton.Create(Panel);
  Button.Parent := Panel;
  RichViewEdit1.AddControl('', Panel);
Now, if you copy this panel in TRichViewEdit, its copy will be pasted together with a button.

But for frames, this is a problem. When a frame is constructed, it is constructed together with subcomponents. So, when loading a frame, its subcomponents are created twice: when a pasted frame is constructed, and when its properties (including subcomponents) are read. As a result "component named NNN already exist" error occurs.
There is a workaround: set the global variable RichViewWriteControlIgnoreChildren := True (defined RVFMisc unit). In this mode, subcomponents will not be stored in RVF.
Because of this a panel from the example below will be saved and loaded without a button. However, frames will be saved and loaded correctly.

I do not know an elegant solution for this problem that would handle the both cases at the same time.

Posts: 2
Joined: Wed Nov 27, 2019 10:14 pm

Re: VCL Frames inserted into TRichViewEdit

Post by Lex » Tue Dec 03, 2019 10:00 pm

Thanks Sergey,

I had noticed the "component named NNN already exist" error, so I was attempting to adjust my frame in such a way that all of its subcomponents had blank names. However, as you can imagine this isn't very elegant when you need to access any of its subcomponents. Even if I had gotten this to work the subcomponents would have been created twice which isn't desirable :? .

Your suggestion of setting 'RichViewWriteControlIgnoreChildren := True' has done exactly what I require for now as the only control I wish to embed is my frame. Thanks heaps for the great support! :D

Post Reply