Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-08

how to remove comments (TSynIniSyn)?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Junior

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.

thanks

Reply by email

Martin
to Junior
Junior wrote 6 lines
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;

Reply by email

Mattias Gaertner
to Junior: hello all :) I would like to open a file .ini in one TSynEdit removing all existing…
Show quoted text 6 lines
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.

There are various definitions what a comment is in an ini file.

If you want to delete all lines starting with a semicolon:

for i:=SynEdit1.Lines.Count-1 downto 0 do
  if LeftStr(SynEdit1.Lines[i],1)=';' then
    SynEdit1.Lines.Delete(i);

Mattias

Reply by email