EControl Ltd. Forum Index EControl Ltd.
VCL libraries and software support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Prevent Autoreplace in Comments

 
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor
View previous topic :: View next topic  
Author Message
jfudickar



Joined: 12 Jun 2006
Posts: 38
Location: Eschborn, Germany

PostPosted: Mon Jun 09, 2008 8:34 am    Post subject: Prevent Autoreplace in Comments Reply with quote

Hi Michael,

is it possible to prevent the autoreplace inside of comments?

Greetings
Jens
Back to top
View user's profile Send private message Visit poster's website
econtrol
Site Admin


Joined: 09 Jun 2006
Posts: 202

PostPosted: Mon Jun 09, 2008 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jfudickar



Joined: 12 Jun 2006
Posts: 38
Location: Eschborn, Germany

PostPosted: Mon Jun 09, 2008 9:41 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
econtrol
Site Admin


Joined: 09 Jun 2006
Posts: 202

PostPosted: Wed Jun 11, 2008 7:44 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group