View previous topic :: View next topic |
Author |
Message |
jfudickar
Joined: 12 Jun 2006 Posts: 38 Location: Eschborn, Germany
|
Posted: Mon Jun 09, 2008 8:34 am Post subject: Prevent Autoreplace in Comments |
|
|
Hi Michael,
is it possible to prevent the autoreplace inside of comments?
Greetings
Jens |
|
Back to top |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Mon Jun 09, 2008 2:41 pm Post subject: |
|
|
Hi Jens,
Yes, it is possible using OnAutoReplace event.
Using APos parameter you may find token (SyntaxMemo.SyntObj.TokenAtPos) and define its type. If it is comment set Accept to False.
Michael. |
|
Back to top |
|
|
jfudickar
Joined: 12 Jun 2006 Posts: 38 Location: Eschborn, Germany
|
Posted: Mon Jun 09, 2008 9:41 pm Post subject: |
|
|
Hi Michael,
thanks.
I'm using the following code:
Code: |
procedure TGlobalOptionsDataModule.SyntAutoReplaceFilledAutoReplace(APos:
Integer; const AWord: string; var AReplace: string; var Accept: Boolean);
var
token: Integer;
Memo: TCustomSyntaxMemo;
TokenType: Integer;
begin
Memo := SyntAutoReplaceFilled.SyntMemo;
if not Assigned(Memo) then
Exit;
token := Memo.SyntObj.TokenAtPos(APos);
if token <> -1 then
TokenType := Memo.SyntObj.Tags[Token].TokenType;
if Assigned(Memo.TextSource) and Assigned(memo.TextSource.SyntaxAnalyzer) then
if Pos('COMMENT', Uppercase(memo.TextSource.SyntaxAnalyzer.TokenTypeNames[TokenType])) > 0 then
Accept := False;
end;
|
Is it ok, or did you know a better way.
Greetings and thanks
Jens |
|
Back to top |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Wed Jun 11, 2008 7:44 am Post subject: |
|
|
Hi Jens,
Yes, it is ok.
But you need not next check:
Code: | if Assigned(Memo.TextSource) and Assigned(memo.TextSource.SyntaxAnalyzer) then |
You may access analyzer:
Code: | memo.SyntObj.Owner.TokenTypeNames |
Also if you use predefined lexer it is better to compare TokenType with predefined constant.
So next code will be better:
Code: | procedure TGlobalOptionsDataModule.SyntAutoReplaceFilledAutoReplace(APos:
Integer; const AWord: string; var AReplace: string; var Accept: Boolean);
const TokIdx_Comment = 1;
var token: Integer;
Memo: TCustomSyntaxMemo;
begin
Memo := SyntAutoReplaceFilled.SyntMemo;
if Assigned(Memo) and Assigned(Memo.SyntObj) then
begin
token := Memo.SyntObj.TokenAtPos(APos);
Accept := (token = -1) or (Memo.SyntObj.Tags[Token].TokenType <> TokIdx_Comment);
end;
end; |
Michael. |
|
Back to top |
|
|
|