2017-10-03 13 views
1

Delphi 플러그인을 사용하여 RAD Studio에서 Delphi 코드를 강조하려고합니다. 편집기에서 코드를 가져 오려면 OpentoolsAPI을 사용합니다.RAD Studio에서 델파이 코드 강조하기

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

어떤 델파이 버전을 사용하고 있습니까? – 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; 

이 알림을 사용하여 사용자의 관심을 끌기 위해 캔버스로 무언가를 그릴 수 있습니다.