Recent

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

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #15 on: March 06, 2015, 04:30:59 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?
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, 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!

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #16 on: March 06, 2015, 04:35:18 pm »
ok, so here's the topic 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...

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2285
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #17 on: March 06, 2015, 05:18:32 pm »
Actually my idea was to write a procedure for adding a formatted text, like in this post, 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 to implement the desired functionality.
« Last Edit: March 06, 2015, 05:45:04 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

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

kuzja

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

kuzja

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

skalogryz

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

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2285
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #22 on: March 09, 2015, 04:11:57 am »
r4011 should fix the issue with gtk2
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

avra

  • Hero Member
  • *****
  • Posts: 1717
    • Additional info
Re: RichMemo - more detailed doc?
« Reply #23 on: March 10, 2015, 09:31:45 am »
Actually my idea was to write a procedure for adding a formatted text, like in this post, 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
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #24 on: March 10, 2015, 09:30:48 pm »
Actually my idea was to write a procedure for adding a formatted text, like in this post, 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. :)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2285
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #25 on: March 10, 2015, 09:54:00 pm »
please let me know when you retest SetTextAttributes with TFont on the newer revision.
It should work for gtk2
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #26 on: March 10, 2015, 10:18:35 pm »
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:
Code: [Select]
  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...



skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2285
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #27 on: March 12, 2015, 05:11:40 am »
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".
« Last Edit: March 12, 2015, 05:29:01 am by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

kuzja

  • New Member
  • *
  • Posts: 20
Re: RichMemo - more detailed doc?
« Reply #28 on: March 13, 2015, 10:54:23 am »
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...  :(
Quote
-- 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!

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2285
    • havefunsoft.com
Re: RichMemo - more detailed doc?
« Reply #29 on: March 13, 2015, 01:13:23 pm »
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.

Patron Cocoa Widgetset development https://www.patreon.com/skalogryz