Problem: You MUST inherit SynEdit It only works by accessing protected fields.
You either create a new component (via package menu) and register your synedit, or you create in in code.
Only works, if there is a line.
For backgroundcolor, line can be empty. Frame has a bug, and does draw incorrect, unless there is text
You still need to do an handler to update the pos, if the caret moves
I do recommend to use the Identifier dictionary (laz trunk, may need package cody installed), you can find stuff from all units, and it does add units to your uses.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
SynEdit, SynEditPointClasses, SynEditMarkupSelection, SynEditTypes, SynEditMarkup;
type
{ TMySyn }
TMySyn = class(TSynEdit)
private
FMyBlock: TSynEditSelection;
fMyMarkup: TSynEditMarkupSelection;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
FMySyn: TMySyn;
end;
var Form1: TForm1;
implementation
constructor TMySyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyBlock := TSynEditSelection.Create(ViewedTextBuffer, FAlse);
FMyBlock.InvalidateLinesMethod := @InvalidateLines;
fMyMarkup := TSynEditMarkupSelection.Create(self, FMyBlock);
TSynEditMarkupManager(MarkupMgr).AddMarkUp(fMyMarkup);
end;
destructor TMySyn.Destroy;
begin
FreeAndNil(FMyBlock);
FreeAndNil(fMyMarkup);
inherited Destroy;
end;
{$R *.lfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FMySyn := TMySyn.Create(self);
FMySyn.Parent:= self;
FMySyn.Align := alClient;
with FMySyn do begin
FMySyn.text := 'ouaueuioeiuueiaoeuouoeauoeua' + LineEnding +'ouaueuioeiuueiaoeuouoeauoeua' + LineEnding +'ouaueuioeiuueiaoeuouoeauoeua' + LineEnding ;
FMyBlock.StartLineBytePos := Point(5,2);
FMyBlock.EndLineBytePos := Point(15,2);
fMyMarkup.Enabled := True;
fMyMarkup.MarkupInfo.FrameColor := clRed;
fMyMarkup.MarkupInfo.FrameEdges := sfeAround;
fMyMarkup.MarkupInfo.FrameStyle := slsSolid;
//fMyMarkup.MarkupInfo.Background := clSilver;
end;
end;
end.