Autor Beitrag
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 13.06.03 19:37 
Hi,

über folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  procedure EliminateComments;
  var
    i: Integer;
  begin
    for i := Form1.RichEdit2.Lines.Count downto 0 do begin
      if (Form1.RichEdit2.Lines[i] = '') then begin
        Form1.RichEdit2.Lines.Delete(i);
        continue;
        end;
      if Form1.RichEdit2.Lines[i][1] = '!' then
        Form1.RichEdit2.Lines.Delete(i);
      end;


eliminiere ich alle Leerzeilen und all jene Zeilen, die mit einem "!" beginnen, aus meinem RichEdit. Das klappt wunderbar - bis, ja bis das der Inhalt des RichEdit nicht mehr ohne Scrollbar angezeigt werden kann. Dann aber versagt der Quelltext und lässt mittendrin einfach ein paar Zeilen aus.
Ich schätze mal, dass das ein Delphi-Bug is (bzw. ein Bug in TRichEdit), weil der selbe Code bei einem Memo funktioniert. Was kann ich tun, damit ich nicht zur Laufzeit ein Memo erstellen muss, damit mein Code richtig funktioniert?

AXMD
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Fr 13.06.03 19:55 
Hallo,

Dir ist schon bewusst, das du mit einer for schleife immer nur quasi jede zweite zeile erwischt, wenn du eine löscht?
Beispiel

Zeile A
Zeile B
Zeile C
Zeile D

Dann hat Zeile A den index 0 usw. Stell dir nun vor, du löscht Zeile B ( also index 1), was passiert, Zeile C hat nach dem löschen von Zeile B den index 1, die forschleife zählt aber anschließend um eins hoch, das bedeutet, Zeile C wird nicht abgeprüft. Nimm lieber eine While-Schleife und erhöhe deine Zählvariable nur, wenn du kein Delete ausführst...
Vielleicht ist schon da dein problem

Gruß
Ken
mars
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 238

Debian Woody, Win 2000, Win XP
D7 Ent, Kylix 3
BeitragVerfasst: Fr 13.06.03 20:36 
@Cenbells: Schau dir mal die For-Schleife genau an...downto... :wink:
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Sa 14.06.03 10:30 
@mars, ok *G* Das habe ich übersehen... :lol:
AXMD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 16.06.03 13:46 
Hi,

testet den Code doch bitte mal. Bei mir funzt er in jedem Memo, aber in keinem Richedit.
Weiß niemand, woran das liegen könnte?

AXMD
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Mi 18.06.03 10:05 
das könnte daran liegen, daß in einem Richedit noch Rt Formatierungen drin stecken, die du aber nicht sehen kannst. Warum nimmst du nicht die Komponente SynEdit?

Gruß
Ken