Recent

Author Topic: RichMemo - more detailed doc?  (Read 20374 times)

kuzja

  • New Member
  • *
  • Posts: 20
RichMemo - more detailed doc?
« 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!
« Last Edit: March 06, 2015, 03:47:02 pm by kuzja »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: RichMemo - more detailed doc?
« Reply #1 on: March 06, 2015, 12:53:09 pm »

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #2 on: March 06, 2015, 01:26:46 pm »
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... ;)

Zoran

  • Hero Member
  • *****
  • Posts: 1461
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: RichMemo - more detailed doc?
« Reply #3 on: March 06, 2015, 01:44:27 pm »
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/

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #4 on: March 06, 2015, 02:05:33 pm »
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.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: RichMemo - more detailed doc?
« Reply #5 on: March 06, 2015, 02:14:40 pm »
What exactly is the problem you have with SetTextAttributes?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #6 on: March 06, 2015, 02:15:03 pm »
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.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #7 on: March 06, 2015, 02:39:01 pm »
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.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #8 on: March 06, 2015, 02:48:30 pm »
hmm, was the range actually deleted or just font size became really small (1pt or 0pt)?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #9 on: March 06, 2015, 03:03:10 pm »
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?

« Last Edit: March 06, 2015, 03:05:51 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #10 on: March 06, 2015, 03:29:47 pm »
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...

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #11 on: March 06, 2015, 03:40:43 pm »
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.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #12 on: March 06, 2015, 03:43:59 pm »
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.

Quote
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:
Code: [Select]
  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)
« Last Edit: March 06, 2015, 03:47:48 pm by kuzja »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #13 on: March 06, 2015, 03:52:13 pm »
Well, if need to get the font from RichMemo itself I'd suggest the following code.
Code: [Select]
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?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #14 on: March 06, 2015, 04:08:49 pm »
ok, so here's the topic that explains how to resolve the actual font data
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz