Einzelnen Beitrag anzeigen

Christian Seehase
(Co-Admin)

Registriert seit: 29. Mai 2002
Ort: Hamburg
11.105 Beiträge
 
Delphi 11 Alexandria
 
#20
  Alt 1. Nov 2002, 14:25
Moin Rebugger,

da auch dynamische Arrays wieder freigegeben werden müssen, hätte ich da noch zwei Vorschläge.

1. Mit Luckies Parse / TZeile

Code:
[b]function[/b] TMain.Intialize_Highlight(Highlight: TSynHighlighterAttributes; Section: [b]String[/b]; Part: [b]String[/b]; Standard: [b]String[/b]): Bool;
[b]var[/b]
  ini: TIniFile;
  tmp_style: TZeile;
[b]begin[/b]
  ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'highlight.cfg');
  [b]try[/b]
    tmp_style := Parse(ini.ReadString(Section,Part,Standard), 0);
    [b]try[/b]
      Highlight.Foreground := StrToInt(tmp_style[0]);
      Highlight.Background := StrToInt(tmp_style[1]);

      [b]if[/b] StrToInt(tmp_style[2]) = 1 [b]then[/b]
        Highlight.Style := [fsBold];
      [b]if[/b] StrToInt(tmp_style[3]) = 1 [b]then[/b]
        Highlight.Style := [fsItalic];
      [b]if[/b] StrToInt(tmp_style[4]) = 1 [b]then[/b]
        Highlight.Style := [fsUnderline];
      [b]if[/b] StrToInt(tmp_style[5]) = 1 [b]then[/b]
        Highlight.Style := [fsStrikeOut];
    [b]finally[/b]
      finalize(tmp_style);
      FreeAndNil(tmp_style);
    [b]end[/b];
  [b]finally[/b]
    ini.Free;
  [b]end[/b];
  result := TRUE;
[b]end[/b];
2. Mit einer TStringList statt array of string und StringReplace statt Parse

Code:
[b]function[/b] TMain.Intialize_Highlight(Highlight: TSynHighlighterAttributes; Section: [b]String[/b]; Part: [b]String[/b]; Standard: [b]String[/b]): Bool;
[b]var[/b]
  ini: TIniFile;
  tmp_style: TStringList;
[b]begin[/b]
  ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'highlight.cfg');
  [b]try[/b]
    tmp_style := TStringList.Create;
    [b]try[/b]
      tmp_style := StringReplace(ini.ReadString(Section,Part,Standard),',',#13#10,[rfReplaceAll]);
      Highlight.Foreground := StrToInt(tmp_style[0]);
      Highlight.Background := StrToInt(tmp_style[1]);

      [b]if[/b] StrToInt(tmp_style[2]) = 1 [b]then[/b]
        Highlight.Style := [fsBold];
      [b]if[/b] StrToInt(tmp_style[3]) = 1 [b]then[/b]
        Highlight.Style := [fsItalic];
      [b]if[/b] StrToInt(tmp_style[4]) = 1 [b]then[/b]
        Highlight.Style := [fsUnderline];
      [b]if[/b] StrToInt(tmp_style[5]) = 1 [b]then[/b]
        Highlight.Style := [fsStrikeOut];
    [b]finally[/b]
      FreeAndNil(tmp_style);
    [b]end[/b];
  [b]finally[/b]
    ini.Free;
  [b]end[/b];
  result := TRUE;
[b]end[/b];
Tschüss Chris
Die drei Feinde des Programmierers: Sonne, Frischluft und dieses unerträgliche Gebrüll der Vögel.
Der Klügere gibt solange nach bis er der Dumme ist
  Mit Zitat antworten Zitat