Lazarus
Programming => Packages and Libraries => RichMemo => Topic started by: kuzja on March 06, 2015, 12:48:55 pm
-
Hello,
I am running Lazarus 1.2.6 under Linux Mint 17.1.
I've successfully installed RichMemo and started experimenting with my first application. As my source of information I've used the Lazarus wiki page:
http://wiki.lazarus.freepascal.org/RichMemo
Unfortunately, RichMemo does not behave as expected. Now I am not sure if I am doing something wrong or if there are some bugs. Is there a more detailed documentation on RichMemo methods, properties, etc.? I could not find any...
If needed, I can provide more info on what isn't working for me, of course.
Thanks for help!
-
Do you know lzRichEdit?
http://wiki.lazarus.freepascal.org/lzRichEdit
-
Do you know lzRichEdit?
http://wiki.lazarus.freepascal.org/lzRichEdit
Well, it is one of the components I took in consideration. But before I switch to another component, I'd like to know what is the problem with RichMemo. Because I believe every component has its own problems, and installing another component just brings a different set of troubles... ;)
-
According to the author of the component, you should use svn version from https://svn.code.sf.net/p/lazarus-ccr/svn/components/richmemo/
If you don't use (or don't want to install) svn client, you can download the latest revision here (by clicking on "Download Snapshot" link): http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/richmemo/
-
According to the author of the component, you should use svn version from https://svn.code.sf.net/p/lazarus-ccr/svn/components/richmemo/
...
Thanks for the info. That's exactly what I did.
The problem is not in the installation, RichWiew basically works, but I have problems when using some of the methods (namely SetTextAttributes). Therefore I am looking for a more detailed documentation, to be sure I haven't made any mistakes.
-
What exactly is the problem you have with SetTextAttributes?
-
The problem is not in the installation, RichWiew basically works, but I have problems when using some of the methods (namely SetTextAttributes). Therefore I am looking for a more detailed documentation, to be sure I haven't made any mistakes.
Go ahead what kind of details are you looking for?
TextStart - is the starting position of the text (that's matching cursor position)
TextLen - is that's number of characters in the text (a line space character always counts as a single character. InsertablObjects are also a single character).
TextParams - the structure containing font information.
and it goes like this:
TFontParams
* Name - font family name
* Size - size of the font in points
* Color - font color
* Style - font styles (a combination of possible values: Bold, Italic, Strike-Out, Underline)
* HasBkClr - flag if a background color (highlight) should be applied to the text
* BkColor - background color.
It's strongly recommended to initialize TFontParams with InitFontParams() procedure call, since all fields of the record must have valid values.
There's also an overloaded convenience method SetTextAttributes() that accepts TFont (standard for LCL) rather than TFontParams. This method would initialize TFontParams for you.
-
Okay, here is the description of my problem:
In my understanding, SetRangeColor method is a special case of the SetTextAttributes method - both have the starting character and the length as arguments; the former should apply just the color to the range, the latter should change all TFormParams (or TFont properties, respectively) accordingly.
When I wrote a simple application using SetRangeColor, it worked as expected.
Then I changed the call to SetRangeColor to SetTextAttributes (the overloaded version with TFont), where the font was the same except for color. I expected the code to do the same as before, but the result was that the range was deleted instead.
What's wrong?
Thanks in advance.
-
hmm, was the range actually deleted or just font size became really small (1pt or 0pt)?
-
SetRangeColor works a bit different than SetTextAttributes.
SetRangeColor goes from the specified range of characters and only changes the font. It doesn't touch any other attributes (style, size of font name).
Thus if you'd apply color using SetRange color to portion of the text
This text should keep bold.
The result might be as
This text should keep bold.
By if you'd just apply SetTextAttributes then the result could be like this
This text should keep bold.
In case of TFont usage, you'd need to make sure that the class is initialized. I.e. Font name is a valid name as well as size is not 0.
What OS are you working on?
-
hmm, was the range actually deleted or just font size became really small (1pt or 0pt)?
Good question. Copying the contents of RichMemo window to clipboard and pasting it in pure text editors shows that the characters are NOT actually deleted...
And the TFont variable used as an argument has its Size=0, so the problem does not really lie in the SetTextAttributes method...
But what is strange, checking RichView.Font.Size shows 0 as well, though the text is drawn correctly until my call to SetTextAttributes is done...
-
I wonder if this is LCL behavior to set TFont to "system defaults" by initializing size to 0 and setting font name to "default".
I'm not sure what's the best way to get actual values for TFont structure.
-
SetRangeColor works a bit different than SetTextAttributes.
SetRangeColor goes from the specified range of characters and only changes the font. It doesn't touch any other attributes (style, size of font name).
Yes, I understand. I haven't realized the difference, but anyway, it is not directly related to my problem.
In case of TFont usage, you'd need to make sure that the class is initialized. I.e. Font name is a valid name as well as size is not 0.
What OS are you working on?
The code goes as follows:
f:=TFont.Create;
...
f.Assign(RichMemo1.Font);
f.Color:=clBlue;
with RichMemo1 do
SetTextAttributes(SelStart,SelLength,f);
...
f.Free;
So hopefully the initialization should be ok.
But as I wrote in the previous post, for some reason RichMemo1.Font.Size=0, so f.Size=0 as well...
My OS is Linux Mint 17.1. (Sorry for the error in my very first post, where I wrote 13.1 :( - now corrected)
-
Well, if need to get the font from RichMemo itself I'd suggest the following code.
var
p : TFontParams;
begin
RichMemo1.GetTextAttributes(RichMemo1.SelStart, p);
p.Color:=clBlue;
RichMemo1.SetTextAttributes(RichMemo1.SelStart, RichMemo1.SelLength, p);
It's more light weight, since it doesn't allocate TFont structure.
Though, I think it might not be exactly what you want, since you might be looking for default font parameters?
-
ok, so here's the topic (http://forum.lazarus.freepascal.org/index.php?topic=16697.0) that explains how to resolve the actual font data
-
Well, if need to get the font from RichMemo itself I'd suggest the following code.
var
p : TFontParams;
begin
RichMemo1.GetTextAttributes(RichMemo1.SelStart, p);
p.Color:=clBlue;
RichMemo1.SetTextAttributes(RichMemo1.SelStart, RichMemo1.SelLength, p);
It's more light weight, since it doesn't allocate TFont structure.
Though, I think it might not be exactly what you want, since you might be looking for default font parameters?
Yes, that's what I started to thing of as a workaround. But I would make another mistake, as I would allocate TFontParams variable in the same way as I did TFont before...
You are right the idea was to get default font parameters. On the other hand, as I want to use the formatting on a freshly added text, it should have the defaults, so the workaround using GetTextAttributes should work, I suppose.
Actually my idea was to write a procedure for adding a formatted text, like in this post (http://forum.lazarus.freepascal.org/index.php/topic,19446.0.html), but more general in the sense it would add a formatted string to the same line, without creating a newline. I will try your suggestion and let you know the result.
Thanks again!
-
ok, so here's the topic (http://forum.lazarus.freepascal.org/index.php?topic=16697.0) that explains how to resolve the actual font data
Well, it might work, but seems a bit cumbersome to me... :)
What I would like is to easily fill a TFont or TFontParams variable with RichMemo's default font parameters...
-
Actually my idea was to write a procedure for adding a formatted text, like in this post (http://forum.lazarus.freepascal.org/index.php/topic,19446.0.html), but more general in the sense it would add a formatted string to the same line, without creating a newline. I
omg! why in the world did I overlook this topic?! :'(...hah it's two years old. nevermind!
RichMemoUtils has additional functions (http://wiki.freepascal.org/RichMemo#InsertStyledText.2CInsertColorStyledText.2CInsertFontText) to implement the desired functionality.
-
Well, it might work, but seems a bit cumbersome to me... :)
What I would like is to easily fill a TFont or TFontParams variable with RichMemo's default font parameters...
r4001 should work fine for SetAttributedText with TFont passed. No more extra tiny characters :D
-
Well, it was strange to me there are no such methods available. ;)
On the other hand, as a learning example, this was a good exercise. :)
I am sorry I was not patient enough to read the whole wiki page. I will definitely try to use the RichMemoUtilities. The usual question is, do I need some more info, or should I do with the wiki page? Are the utils already installed together with the RichMemo package? I tried to add uses RichMemoUtilities; clause, but it failed.
As to the proposed solution using GetTextAttributes:
It seems to work, with one exception. The returned value of p.BkGround (p: TFontParams) is not "white" (nor anything similar), but a strange (sometimes even negative) value which seems to change more or less randomly. Indeed, using p in SetTextAttributes then results in incorrect text background.
Thank you for your time!
-
Well, it might work, but seems a bit cumbersome to me... :)
What I would like is to easily fill a TFont or TFontParams variable with RichMemo's default font parameters...
r4001 should work fine for SetAttributedText with TFont passed. No more extra tiny characters :D
Thanks a lot! I will upgrade and try it asap, but it might be no sooner than next week... I will be back then.
-
The usual question is, do I need some more info, or should I do with the wiki page?
Go with the wiki page for now. If you've any question - feel free to ask and I'll try to answer them... very likeon the wiki too.
Are the utils already installed together with the RichMemo package? I tried to add [b]uses RichMemoUtilities;[/b] clause, but it failed.
sorry the unit name is RichMemoUtils.
As to the proposed solution using GetTextAttributes:
It seems to work, with one exception. The returned value of p.BkGround (p: TFontParams) is not "white" (nor anything similar), but a strange (sometimes even negative) value which seems to change more or less randomly. Indeed, using p in SetTextAttributes then results in incorrect text background.
Sounds like a bug in to me. GetTextAttributes should set HasBkClr to false, preventing the usage of bkcolor.
-
r4011 should fix the issue with gtk2
-
Actually my idea was to write a procedure for adding a formatted text, like in this post (http://forum.lazarus.freepascal.org/index.php/topic,19446.0.html), but more general in the sense it would add a formatted string to the same line, without creating a newline.
Have you checked wiki recently? Few days ago I have added 3 examples how to append colorized text with or without newline:
http://wiki.freepascal.org/RichMemo#Append_mixed_color_text_at_the_end_of_the_RichMemo
-
Actually my idea was to write a procedure for adding a formatted text, like in this post (http://forum.lazarus.freepascal.org/index.php/topic,19446.0.html), but more general in the sense it would add a formatted string to the same line, without creating a newline.
Have you checked wiki recently? Few days ago I have added 3 examples how to append colorized text with or without newline:
http://wiki.freepascal.org/RichMemo#Append_mixed_color_text_at_the_end_of_the_RichMemo
Hello,
Yes, I've seen the examples and they surely have helped me to understand the principles. But they use SetRangeColor method, and I wanted to change the font style as well. So I used SetTextAttributes method instead, and ran into problems which are discussed above in this thread.
Thanks anyway. :)
-
please let me know when you retest SetTextAttributes with TFont on the newer revision.
It should work for gtk2
-
To skalogryz:
I've installed r4013 today and made some tests.
- Using GetTextAttributes now works correctly, with no background color problems.
- Using SetTextAttributes with TFont variable still does not work as expected. The code is something like this:
f:=TFont.Create;
...
f.Assign(RichMemo1.Font);
f.Color:=clBlue;
f.Style:=[fsItalic];
with RichMemo1 do
SetTextAttributes(SelStart,SelLength,f);
...
f.Free;
Now the selected text does not "disappear" (size is not set to 0), which is fine, but neither color, nor style are set as required - they are set to default instead.
Examining the run-time values it seems there are actually two problems:
-- f.Assign(RichMemo1.Font) does not set the f variable correctly - e.g. the size is still set to 0.
-- When SetTextAttributes method is called with f as TFont parameter, it uses GetFontParams function to convert TFont variable to TFontParams structure. This function appears to correct some damage caused by the former error ("repairs" the font name and size), but for some reason, does not set the color and style correctly...
I've also made tests with RichMemoUtils. As they use GetTextAttributes method, they were affected by the "background color error" as well, but in the new release they work ok. :)
Thanks for your support. I hope I haven't made some silly mistake during the above tests...
-
You, sir, have a talent for opening cans of worms! :D
r4017 should address the issues with styling and color.
-- f.Assign(RichMemo1.Font) does not set the f variable correctly - e.g. the size is still set to 0.
Sorry, there's little or nothing I can do. This is how LCL behaves, it just copies the initial "default" data, without actual resolving of names and sizes. The resolving is happening when TFontParams is initialized. However, if f.Name is set to something and Size is left unmodified, I presume you'll observer letters "disappearing".
-
You, sir, have a talent for opening cans of worms! :D
r4017 should address the issues with styling and color.
Ehm... it would be really nice to close that can... :)
Installed r4019 and retested SetTextAttributes(...TFont). If Style set to fsItalic, fsUnderline or fsStrikeOut, it works. If set to fsBold, does not work... :(
-- f.Assign(RichMemo1.Font) does not set the f variable correctly - e.g. the size is still set to 0.
Sorry, there's little or nothing I can do. This is how LCL behaves, it just copies the initial "default" data, without actual resolving of names and sizes. The resolving is happening when TFontParams is initialized. However, if f.Name is set to something and Size is left unmodified, I presume you'll observer letters "disappearing".
I fully understand that. I think I will keep to TFontParams unless I really need TFont for some reason.
Thanks!
-
Ehm... it would be really nice to close that can... :)
Installed r4019 and retested SetTextAttributes(...TFont). If Style set to fsItalic, fsUnderline or fsStrikeOut, it works. If set to fsBold, does not work... :(
This is odd. I tested on the full style set. I'll double check.
-
Ehm... it would be really nice to close that can... :)
Installed r4019 and retested SetTextAttributes(...TFont). If Style set to fsItalic, fsUnderline or fsStrikeOut, it works. If set to fsBold, does not work... :(
This is odd. I tested on the full style set. I'll double check.
I repeated the test, with the same result.
This works:
var p: TFontParams;
...
RichMemo1.GetTextAttributes(RichMemo1.SelStart, p);
p.Color:=clBlue;
p.Style:=[fsBold];
RichMemo1.SetTextAttributes(RichMemo1.SelStart, RichMemo1.SelLength, p);
This does not work (i.e. it sets the color to blue, but the style is default, not bold):
var f: TFont;
...
f:=TFont.Create;
...
f.Assign(RichMemo1.Font);
f.Color:=clBlue;
f.Style:=[fsBold];
with RichMemo1 do
SetTextAttributes(SelStart,SelLength,f);
...
f.Free;
Odd it is, that's true...
-
what happens if you use
f.Style:=[fsBold,fsItalic];
?
-
what happens if you use
f.Style:=[fsBold,fsItalic];
?
Text style is italic, but not bold.
-
Was testing with not very slim font! r4025 should have the issue with the bond font fixed!
Btw, after the update, please do the following Project -> View Project Source
In the uses section you should find "richmemopackage". Please remove it from the uses section.
It has nothing todo with the font issues, but it will save you up to 400Kb in the stripped executable (gtk2). As well as might save some milliseconds on compilation.
-
Was testing with not very slim font! r4025 should have the issue with the bond font fixed!
I've made only a simple test, but it seems to be okay now. :)
Thanks for your effort! :)
Btw, after the update, please do the following Project -> View Project Source
In the uses section you should find "richmemopackage". Please remove it from the uses section.
It has nothing todo with the font issues, but it will save you up to 400Kb in the stripped executable (gtk2). As well as might save some milliseconds on compilation.
Thanks for the tip :)
-
Another thing I would like to ask about are the TAB stops in RichMemo... But I suppose it would be more correct to start a new topic for that, wouldn't it? :)
-
Another thing I would like to ask about are the TAB stops in RichMemo... But I suppose it would be more correct to start a new topic for that, wouldn't it? :)
sure, tabs can be added. It was on my todo list anyway. And feel free to start a new topic.
-
Before I start the new topic, I have one more question, please.
With WordWrap=true, I set RichMemo ScrollBars property to ssNone (both in design and run time), but the vertical scrollbar is still shown when the number of lines exceeds the size of RichMemo window (as if set to Auto).
Can I make the scrollbar disappear somehow?
Thanks again. :)
-
another visual bug. Let me see if I can fix it.
-
r4040 starts tab stops. But currently win32 is the only widgetset that implements them.
-
r4044 tab stops (http://wiki.freepascal.org/RichMemo#SetParaTabs) for gtk2. Issues with srollbars should be fixed.
-
r4044 tab stops (http://wiki.freepascal.org/RichMemo#SetParaTabs) for gtk2. Issues with srollbars should be fixed.
Scrollbars seem to be ok now. But during the test I noticed that word wrap is active even if WordWrap property is set to false. Could there be something I overlooked...?
Now I am going to experiment with the tab stops... man, I am curious :)
-
ugh. That's because WordWrap is hard-coded to be enabled.
Will fix that... why did I do that in the first place?! This is hard to notice, until scrollbars are working as defined by properties :)
-
Just want to report my first experience with the tab stops is positive. :)
I have also noticed that there is some kind of "automatic tabbing" in case there are more actual TAB characters in the text line than is the number of the defined tab stops. This is fine, but I suggest it should be documented, as it affects the layout of the text also in case a part of it is too big to fit in the predefined tab stops. If one is not aware of this behaviour, the output might seem to be buggy at the first glance...
But anyway, there is nothing wrong about it, I suppose. Thumbs up for good work. :)
-
I have also noticed that there is some kind of "automatic tabbing" in case there are more actual TAB characters in the text line than is the number of the defined tab stops. This is fine, but I suggest it should be documented, as it affects the layout of the text also in case a part of it is too big to fit in the predefined tab stops. If one is not aware of this behaviour, the output might seem to be buggy at the first glance...
Yeah... there're tricks about that.
But you're right, if there're more tabs characters than defined by SetTabs the "automatic" tabs are used (Win32 and Gtk2).
Currently they behave differently on each widgetset, so this is a subject to change!
I.e. Win32 would use it's own "default" tab length (which is similar to Open Office Writer or MS Word)
Gtk2 would use the last tab length
Cocoa would just start a new line.
So beware!
I'll document the behavior as soon as it's works on all platforms the same (very likely to reflect what Win32 does).
-
r4047 fixes the issue with wordwrap.
-
I new to Lazarus and trying to convert a Delphi project to Lazarus. I have a problem setting up tabs in RichMemo
I have a procedure like this:
Procedure ShowList(FileName: string; HeaderText: string;
RealInt: boolean; Decimals: integer);
var
TabPositions: TTabStopList;
begin
TabPositions.Count:=3;
TabPositions.Tabs[0].Offset:= 30;
TabPositions.Tabs[1].Offset:= 140;
TabPositions.Tabs[2].Offset:= 200;
ShowList.Editor.SetParaTabs(0, 363, TabPositions);
When I run my application I get Project ... raised exception class ''External: SIGSEGV'
How to be solved?
-
try this:
var
TabPositions: TTabStopList;
begin
TabPositions.Count:=3;
SetLength(TabPositions.Tabs, TabPositions.Count);
TabPositions.Tabs[0].Offset:= 30;
TabPositions.Tabs[1].Offset:= 140;
TabPositions.Tabs[2].Offset:= 200;
ShowList.Editor.SetParaTabs(0, 363, TabPositions);
or this:
var
TabPositions: TTabStopList;
begin
InitTabStopList(TabPosistions, [30,140,200]);
ShowList.Editor.SetParaTabs(0, 363, TabPositions);