2017-10-03 27 views
1

Delphiプラグインを使用してDelphiコードをRAD Studioで強調表示しようとしています。 私はOpentoolsAPIを使ってコードをエディタから取り出します。その後RAD StudioのDelphiコードの強調表示

EditorServices := BorlandIDEServices as IOTAEditorServices; 

Buffer := EditorServices.TopBuffer; 
Editblock := EditorServices.TopView.GetBlock; 
Buffer.EditPosition.Move(1,1); 
Editblock.BeginBlock; 
Editblock.Extend(10,5); 

、カスタムのハイライトを使用するように私に指示FAQオープンツール。 私はここからカスタムのハイライターをコピーしました:http://www.delphi-central.com/syntax_highlighting.aspx

しかし、ドキュメントは非常に限られており、私はこのカスタムハイライターを使用する方法を考え出すことができません。

HighlightServices := BorlandIDEServices as IOTAHighlightServices; 
SimpleHighLight := TSimpleHighlight.Create; 
HighlightServices.AddHighlighter(SimpleHighLight); 

Text := Editblock.Text; //string 
StartClass := 1; //integer 
SyntaxByte := SyntaxOff; //byte 
SyntaxCode := @SyntaxByte; //POTASyntaxCode 

SimpleHighLight.Tokenize(StartClass,Addr(Text),Text.Length, SyntaxCode); 

しかし、それはデモのコード行でアクセス違反エラーが発生: 私は現在試みていることは以下のとおりです。

FillChar(HighlightCodes^, LineBufLen, $E); 

誰かが私に右の実装の例を与えることができます?または私が間違っていることで私を助けてください?

+0

コードを見ると、SysntaxByte(SyntaxCode経由)は少なくともテキストと同じくらい長くなければならず、そうではありません。なぜそれがすべきかについては、わかりません。私はこれが文字で元のテキスト文字にフォーマットコードを適用すると推測しています。 – Dsm

+0

あなたはどちらのDelphiのバージョンを使用していますか? – dummzeuch

+0

10.2東京版 –

答えて

1

ハイライトを使用する方法を探していませんでした。私はそれを働かせることができませんでした。

Luckely私は興味がある人のために、私の問題に他の解決策を見つけた:)

OpenToolsAPIはノーティファイアを追加することが可能となります。例通知者はhttp://www.gexperts.org/examples/IdeNotifier.pasです。

通知者をこの例から自分の通知者に変更する必要がありました。結果は次のようになります。

unit ViewPaintNotifier; 

interface 

uses 
    ToolsAPI, System.Types, Vcl.Graphics; 

type 
    TViewPaintNotifier = class(TInterfacedObject, IOTANotifier, INTAEditViewNotifier) 
    private 
    public 
    constructor Create; 
    destructor Destroy; override; 
    public 
    // INTAEditViewNotifier 
    procedure BeginPaint(const View: IOTAEditView; var FullRepaint: Boolean); 
    procedure EditorIdle(const View: IOTAEditView); 
    procedure EndPaint(const View: IOTAEditView); 
    procedure PaintLine(const View: IOTAEditView; LineNumber: Integer; 
     const LineText: PAnsiChar; const TextWidth: Word; 
     const LineAttributes: TOTAAttributeArray; const Canvas: TCanvas; 
     const TextRect: TRect; const LineRect: TRect; const CellSize: TSize); 
    // IOTANotifier 
    procedure AfterSave; 
    procedure BeforeSave; 
    procedure Destroyed; 
    procedure Modified; 
    end; 

    procedure register(View: IOTAEditView); 
    procedure RemoveNotifier(View: IOTAEditView); 

implementation 

uses 
    System.SysUtils, Vcl.Dialogs, System.Generics.Collections; 

var 
    NotifierIndexDictionary : TDictionary<string,Integer>; 

procedure Register(View: IOTAEditView); 
var 
    Services: IOTAEditorServices; 
    NotifierIndexPair : Tpair<string,Integer>; 
begin 
    if not Assigned(NotifierIndexDictionary) then 
    NotifierIndexDictionary := TDictionary<string,Integer>.create; 
    NotifierIndexPair := NotifierIndexDictionary.ExtractPair(View.Buffer.FileName); 

    if (NotifierIndexDictionary.ExtractPair(View.Buffer.FileName).Value = 0) then 
    begin 
    NotifierIndexDictionary.Add(View.Buffer.FileName,View.addNotifier(TViewPaintNotifier.Create)); 
    end; 
end; 

procedure RemoveNotifier(View: IOTAEditView); 
var 
    Services: IOTAEditorServices; 
begin 
    if (NotifierIndexDictionary.ExtractPair(View.Buffer.FileName).Value > 0) then 
    begin 
    View.RemoveNotifier(NotifierIndexDictionary.ExtractPair(View.Buffer.FileName).Value); 
    NotifierIndexDictionary.Add(View.Buffer.FileName,0); 
    end; 
end; 


{ TViewPaintNotifier } 

constructor TViewPaintNotifier.Create; 
begin 

end; 

destructor TViewPaintNotifier.Destroy; 
begin 

    inherited; 
end; 

procedure TViewPaintNotifier.EditorIdle(const View: IOTAEditView); 
begin 

end; 

procedure TViewPaintNotifier.BeginPaint(const View: IOTAEditView; 
    var FullRepaint: Boolean); 
begin 

end; 

procedure TViewPaintNotifier.EndPaint(const View: IOTAEditView); 
begin 

end; 

procedure TViewPaintNotifier.PaintLine(const View: IOTAEditView; 
    LineNumber: Integer; const LineText: PAnsiChar; const TextWidth: Word; 
    const LineAttributes: TOTAAttributeArray; const Canvas: TCanvas; 
    const TextRect, LineRect: TRect; const CellSize: TSize); 
begin 
    //use the canvas to draw something 
    //LineRect is the position of the line on the canvas, draw it here for every line 
end; 

procedure TViewPaintNotifier.AfterSave; 
begin 

end; 

procedure TViewPaintNotifier.BeforeSave; 
begin 

end; 

procedure TViewPaintNotifier.Destroyed; 
begin 

end; 

procedure TViewPaintNotifier.Modified; 
begin 

end; 

この通知では、私はキャンバスで何かを描いてユーザーの注意を引くことができます。

関連する問題