[Lazarus] how to remove comments (TSynIniSyn)?

Martin lazarus at mfriebe.de
Wed Aug 21 21:30:59 CEST 2013


On 21/08/2013 19:22, Junior wrote:
> hello all :)
>
> I would like to open a file .ini in one TSynEdit removing all existing 
> comments in this file.
>
> Component TSynIniSyn Already added to project.

TsynIniSyn (as all highlighters) only has coloring. It does not 
edit/modify the file.


If you want to remove certain parts of the text in your ini-file, then 
you must do that yourself (or write the code yourself). There is no 
existing function.


What you can do:
- write code that goes through the text of your inifile
- check each line (part of a line) if it is a comment. You can call the 
SynIniSyn from your code to find out.
- If it is, the remove.

A few basic pointers (you will have to do quite some figuring out yourself)

For starting read http://wiki.lazarus.freepascal.org/SynEdit_Highlighter
(ignore folding, just read "The Basics: Returning Tokens and Attributes" )

Then look at  components\synedit\syneditexport.pas
  TSynCustomExporter.ExportRange

it goes through the text, and checks each fragment.

for ONE line:
      Highlighter.StartAtLineIndex(i - 1);
       while not Highlighter.GetEOL do begin
         Attri := Highlighter.GetTokenAttribute;
         Token := Highlighter.GetToken;
...


you can test
   if Attr = SynIniSyn.CommentAttribute

or use
    KIND := GetTokenKind;





More information about the Lazarus mailing list