Recent

Author Topic: [TSynMemo] Set new line color / font style  (Read 4467 times)

totya

  • Hero Member
  • *****
  • Posts: 722
[TSynMemo] Set new line color / font style
« on: April 14, 2015, 10:36:56 pm »
Hi!

Is there any way to set next line color/font style (example: bold) in TSynMemo?

Thanks.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11338
  • Debugger - SynEdit - and more
    • wiki
Re: [TSynMemo] Set new line color / font style
« Reply #1 on: April 14, 2015, 11:32:30 pm »
First:
http://wiki.lazarus.freepascal.org/Lazarus_1.6.0_release_notes#SynMemo_is_now_Deprecated

If you mean like richedit: no.

If you want to highlight a line:
Code: [Select]
SynEdit.OnSpecialLineMarkup
Code: [Select]
procedure TForm1.SynEdit1SpecialLineMarkup(Sender: TObject; Line: integer;
  var Special: boolean; Markup: TSynSelectedColor);
begin
  Special := line = SynEdit1.CaretY+1; // Markup will be applied, if special is true
  Markup.Clear;
  Markup.Style := [fsBold];
end;

"line = SynEdit1.CaretY+1;" That is if "next line" means line below caret.

If you want line 24 then "line = 25"

totya

  • Hero Member
  • *****
  • Posts: 722
Re: [TSynMemo] Set new line color / font style
« Reply #2 on: April 15, 2015, 05:38:29 pm »
Hi!

Thanks for answer, but above code doensn't work:

Code: [Select]
SynEdit.OnSpecialLineMarkup
Result:

Code: [Select]
unit1.pas(47,31) Error: Wrong number of parameters specified for call to "<Procedure Variable>"

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11338
  • Debugger - SynEdit - and more
    • wiki
Re: [TSynMemo] Set new line color / font style
« Reply #3 on: April 15, 2015, 06:53:54 pm »
OnSpecialLineMarkup is an event. You can assign it in the object inspector.

or you can do SynEdit1.OnSpecialLineMarkup := @yourmethod

Where yourmethod is a procedure on a class, having the correct param list (see 2nd code snippet)

totya

  • Hero Member
  • *****
  • Posts: 722
Re: [TSynMemo] Set new line color / font style
« Reply #4 on: April 15, 2015, 08:04:27 pm »
OnSpecialLineMarkup is an event. You can assign it in the object inspector.

Hi!

Okay, I wrote few applications, my largest project contains about five-thousand lines, well, I know what is the event.

Well, I don't see how can I use this event, please write a working example, if possible.
For example: procedure NextLineIsBold; or procedure NextLineTextColor (const color:TColor); etc...

My example (with your event code):
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  SynEdit1.Lines.Add(Edit1.Text);
end;

The second line is bold only. I want to choice, which line is bold, and which line is not.

Quote
Markup will be applied, if special is true

Okay, I think I don't call this event directly, how can I change "special" variable?

ps.: on TSynEdit F1 or ctrl-F1 result is nothing (no help found for...)

Thanks for your help!
« Last Edit: April 15, 2015, 09:38:50 pm by totya »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11338
  • Debugger - SynEdit - and more
    • wiki
Re: [TSynMemo] Set new line color / font style
« Reply #5 on: April 15, 2015, 08:55:27 pm »
See attached.  Line 3 is bold.
Event is set in Object Inspector.

Now I still do not know that you mean by "next line".

The example allows you to apply attributes to any line, but you need to maintain the lines yourself. If lines are edited, you must update.

There is nothing, that would allow you to say add attribute to current line 3, and remember. The text itself does not store any attributes. If you need that its richedit.

There is also a highlighter SynAnySyn but again, you give it fixed points, and they do NOT update if text is edited.

You can write your own highlighter http://wiki.lazarus.freepascal.org/SynEdit_Highlighter
But if you are looking at lines, then maybe a markup  TSynEditMarkup is better.
Or just use the event.


totya

  • Hero Member
  • *****
  • Posts: 722
Re: [TSynMemo] Set new line color / font style
« Reply #6 on: May 15, 2015, 11:21:04 pm »
Hi!

Tahnks for the answer, but seems to me TRichMemo is the better choice of me.

 

TinyPortal © 2005-2018