thank you mars. After much thought i came with this version
  procedure saveInSection();
  var
    ss: TStringDynArray;
    s: string;
    i, si: integer;
    base: TtplSection;
    till: pchar;
    append: boolean;
    sect: PtplSection;
  begin
  till:=pred(bos);
  if till = NIL then till:=pred(strEnd(ptxt));
  if till^ = #10 then dec(till);
  if till^ = #13 then dec(till);
  base.txt:=getStr(ptxt, till);
  // there may be flags after |
  s:=cur_section;
  cur_section:=chop('|', s);
  base.nolog:=ansiPos('no log', s) > 0;
  base.nourl:=ansiPos('private', s) > 0;
  // there may be several section names separated by =
  ss:=split('=', cur_section);
  // handle the main section specific case
  if ss = NIL then addString('', ss);
  // assign to every name the same txt
  for i:=0 to length(ss)-1 do
    begin
    s:=trim(ss[i]);
    append:=ansiStartsStr('+', s);
    si:=getIdx(s);
    if si < 0 then // not found
      sect:=newSection(s)
    else
      begin
      sect:=@sections[si];
      if append then
        begin
        sect.txt:=sect.txt+base.txt;
        continue;
        end;
      end;
    sect^:=base;
    sect.name:=s; // restore this lost attribute
    end;
  end; // saveInSection
// this is replacing createIdx()
function Ttpl.newSection(section:string):PtplSection;
var
  i: integer;
begin
// add
i:=length(sections);
setLength(sections, i+1);
result:=@sections[i];
result.name:=section;
// getIdx just filled 'last' with not-found, so we must update
last.section:=section;
last.idx:=i;
// manage file.EXT sections
if not ansiStartsText('file.', section) then exit;
i:=length(fileExts);
setLength(fileExts, i+2);
delete(section, 1, 4);
fileExts[i]:=section;
fileExts[i+1]:=str_(last.idx);
lastExt.section:=section;
lastExt.idx:=last.idx;
end; // newSection