Use TRichViewEdit as a simple code editor?

General TRichView support forum. Please post your questions here
Post Reply
hsauro
Posts: 3
Joined: Sat Aug 24, 2024 7:27 pm

Use TRichViewEdit as a simple code editor?

Post by hsauro »

I am writing a FMX application and I need a simple editor component that can show line numbers in a gutter and the ability to change the font color of individual bits of text. At the moment I use TMemo which is very limited. TMS have such a component but it’s based on an underlying JavaScript component which would make life difficult I think during deployment to the Mac and Windows. Synedit would work but it’s just for VCL. I can’t find anything else for FMX that can do this.

My question is could TRichViewEdit be used for the role described above? Obviously I would not use most of the functionality that the control would offer but I don’t care about that. I just want something that can show line numbers in a gutter and the ability to change font colors for individual bits of text.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Use TRichViewEdit as a simple code editor?

Post by Sergey Tkachenko »

Text color can be changed, just like any other text attribute.
Line numbers is not a built-in feature but can be implemented using custom drawing events.
I'll provide an example later today.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Use TRichViewEdit as a simple code editor?

Post by Sergey Tkachenko »

Sorry for the delay, an example will be tomorrow.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Use TRichViewEdit as a simple code editor?

Post by Sergey Tkachenko »

This code shows how to draw line numbers in FireMonkey version of TRichView:
viewtopic.php?p=45845#p45845

But if you want to implement not only simple text coloring, but syntax highlighting, it is much more complicated task. In TRichViewEdit, you can change colors only by changing font attributes of the specified text fragment.
There is an implementation of syntax highlighting (TSyntaxRichViewEdit can be found here: https://www.trichview.com/resources/), but it is a very basic example.
hsauro
Posts: 3
Joined: Sat Aug 24, 2024 7:27 pm

Re: Use TRichViewEdit as a simple code editor?

Post by hsauro »

Thanks for getting back. Are the line number painted in a gutter or in the text area of the control? Although even if painted in the text area i assume they aren’t considered part of the text in the control?
hsauro
Posts: 3
Joined: Sat Aug 24, 2024 7:27 pm

Re: Use TRichViewEdit as a simple code editor?

Post by hsauro »

I think I could handle text highlighting, my syntax is relatively simple. I think I’ll try the trial version to see how it goes. If it works out I’ll purchase a copy.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Use TRichViewEdit as a simple code editor?

Post by Sergey Tkachenko »

This example draws line numbers on the left margin. Just make sure that value of LeftMargin property is large enough.
It's only a drawing, so these numbers are not considered as a part of a document.
Post Reply