Embedding TRichView in TRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
VicFan
Posts: 11
Joined: Sun Jul 28, 2019 8:34 pm

Embedding TRichView in TRichViewEdit

Post by VicFan »

Is it possible to embed a TRichView in a TRichViewEdit? I have tired everything I can think of and I can't get Align to work to fill the parent.

Here is what I have tried:

Code: Select all

void __fastcall TForm1::btnEmbedClick(TObject *Sender)
{
	TRichView * rv = new TRichView(RichViewEdit1);
	rv->Parent = RichViewEdit1;
	rv->Style = RVStyle1;
	rv->Align = alClient;
	rv->Format();
	rv->Align = alClient;
}
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Embedding TRichView in TRichViewEdit

Post by Sergey Tkachenko »

Why do you need it?
VicFan
Posts: 11
Joined: Sun Jul 28, 2019 8:34 pm

Re: Embedding TRichView in TRichViewEdit

Post by VicFan »

My first posting to your website a few weeks ago involved using TRichView as a substitute for a local content browser with buttons to hide/show text. I liked you answer well enough to purchase the license and am still working on that project.

TRichView apparently doesn't allow buttons, as far as I have been able to find. TRichViewEdit does and I have complete control with C++ then (redrawing the whole page or whatever at that point). So, one way to implement my original interface looks like embedding TRichViews inside a TRichViewEdit with buttons at the TRichViewEdit level. According to your documentation (I didn't actually try it yet), but if I make the text read only in TRichViewEdit, it forces the buttons to become non-functional, so I can't go pure TRichViewEdit.

It seemed a reasonable expectation that I would be able to embed one of your controls within another of your controls.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Embedding TRichView in TRichViewEdit

Post by Sergey Tkachenko »

TRichView supports buttons. It supports all content that can be added in TRichViewEdit.
But you should not attempt to add controls in TRichView or TRichViewEdit like on a form or a panel. Controls must be added in a document, like text, pictures and tables, using AddControl method.
VicFan
Posts: 11
Joined: Sun Jul 28, 2019 8:34 pm

Re: Embedding TRichView in TRichViewEdit

Post by VicFan »

Attached is a very simple project that was going to make everything I needed to know about the TRichView component clear to me, but I need some help understanding a few things. This is what got me thinking that buttons did not work for TRichView (because it always adds to origin of the RichView control and InsertControl() only has 1 parameter when TRichViewEdit has 3, so I thought perhaps it was only for other controls).

The project is intended to have 3 buttons. Every time you press “Add Text”, it needs to add “Hello” to the next line. Every time you press “Add Button”, it needs to add a button after the text that proceeds it. Every time you press “Add Paragraph”, it needs to add 2 separate lines to the output. It is loosely based on a quick reading and simplification of you Editor 1 demo. But I don’t want to spend a lot of time analyzing the program for things I don’t need now.

Because I couldn’t figure out how you were registering “OnControl”, I just created a hidden button with that name as a quick and dirty workaround. Without the workaround, I get an “out-of-line definition of 'OnControlClick' does not match any declaration in 'TForm1'” error. So, question #1 is: how do I properly add “OnControlClick” to TForm1 without needing my workaround?

Question #2. How do I modify the code so that each click of “Add Text” puts the text on a new line?

Question #3. How do I modify the code the code so that each click of “Add Button” places the button after whatever text proceeds it?

Question #4. Can you add a demo of tabs, where each of the 2 lines are indented by tabs (one indented by 0.25 inches and the other indented by 0.4 inches)?

I like your demos that show the extensive uses RichVIew can be put, but you might want to consider something like the attached as a basis for a "Quick Start" demo to get new users up to speed fast on just the basics.
Attachments
BaseRichView demo.zip
(131.21 KiB) Downloaded 1383 times
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Embedding TRichView in TRichViewEdit

Post by Sergey Tkachenko »

I'll try to make this demo tomorrow
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Embedding TRichView in TRichViewEdit

Post by Sergey Tkachenko »

Answers

1) If you need to assign an event handler in code, it's not necessary to create a control at design time. You can simply implement the proper function (in the private or the public section). It must be void __fastcall and must have the proper parameters.

2) AddNL has the optional third parameter ParaNo. If you do not specify it, -1 is assumed, meaning addition to the end of the last paragraph. If you specify a positive value, it must an index in RVStyle->ParaStyles->Items[]; a new paragraph will be added with attributes specified in this ParaStyle.
I modified your code to pass 0 to this parameter.
Additionally, I changed Format() to FormatTail(). FormatTail is faster: it formats only content that was added after the last call of Format or FormatTail. FormatTail can be used ONLY if new content starts a new paragraph. You can still use Format, FormatTail is used only for efficiency.

3) Use AddControl. If you need to add from new line, specify the index of a paragraph style in ParaNo parameter. If you need to add to the end of the last line, specify -1 there.
Do not use InsertControl. This method is inherited from parent VCL classes and must not be used (in TRichViewEdit, another InsertControl is declared, it is used to insert in the caret position).

4) I added a new button that adds tabbed text. To specify tab stops, you need to add a paragraph style having the proper Tabs, in RVStyle->ParaStyles. My demo shows how to do it in code. The proper paragraph style is created when it is needed (or existing style is reused). You can add this style at designtime instead; or you can create it one time in code before adding content, store its index and use it later.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Embedding TRichView in TRichViewEdit

Post by Sergey Tkachenko »

The modified demo is attached.
Attachments
BaseDemo.zip
(143.67 KiB) Downloaded 1345 times
VicFan
Posts: 11
Joined: Sun Jul 28, 2019 8:34 pm

Re: Embedding TRichView in TRichViewEdit

Post by VicFan »

Thank you. This is extremely useful and very quick "get up to speed" demo for exactly what I needed without reading tons of documentation with minimal code.
Post Reply