Autor Beitrag
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 20:34 
bei folgendem code mit 'hallo' als S krieg ich immer nur eine showmessage mit '5' und auf dem RichEdit nur ein 'h'

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
  procedure ProcColoredText( S: string; var RichEdit: TRichEdit);
    var
      i: integer;
      buffer: string;
      colored, bold, underlined: boolean;
  begin
    colored := false;  bold := false; underlined := false;
    showmessage(inttostr(Length(S)));
    if length(S) <> 0 then
    for i:=0 to length(S) do
    begin
      if S[i] = #3 then begin
        if not colored then
          RichEdit.SelAttributes.Color := clRed;
        colored := true;
      end else
      RichEdit.Lines[RichEdit.Lines.Count] := RichEdit.Lines[RichEdit.Lines.Count] + S[i];
    end;
  end;


warum das? warum arbeitet die for schleif nit richtig ???
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 20:39 
In Zeile 10:  for i:=1 to length(S) do

Was soll die Schleife den geanu machen?
Überprüfe mal die If-Anweisungen, ob die so stimmen.

_________________
Markus Kinzler.


Zuletzt bearbeitet von mkinzler am So 18.06.06 21:15, insgesamt 1-mal bearbeitet
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 20:42 
äh eigentlich stimmt des doch, immer wenn #3 in S[i] steht wird colored gestzt etc. und wenn s nit #3 is dann wird der text stück für stück addiert, oder etwa nit???
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 20:48 
ausblenden Delphi-Quelltext
1:
RichEdit.Lines[RichEdit.Lines.Count-1] := RichEdit.Lines[RichEdit.Lines.Count-1] + S[i];					


Sollte das colored = true nicht in den then-Zweig der 2 If-Anweisung?

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 20:52 
nein, denn es soll immer gesetzt werden wenn #3 gefunden wurde
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 20:55 
folgendes funktioniert auch nicht (geiches ergebnis):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  procedure ProcColoredText2( S: string; var RichEdit: TRichEdit);
    var
      i: integer;
      buffer: string;
      colored, bold, underlined: boolean;
  begin
    colored := false;  bold := false; underlined := false;
    if length(S) <> 0 then
    for i:=0 to length(S) do
    begin
      RichEdit.Lines[RichEdit.Lines.Count] := RichEdit.Lines[RichEdit.Lines.Count] + S[i];
    end;
  end;
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 20:55 
Dann schau dir mal die Zeilen 9 + 11 an.

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 21:08 
hää? bin ich jetzt vollkommen bescheuert??

das das RichEdit.Lines[RichEdit.Lines.Count] := RichEdit.Lines[RichEdit.Lines.Count] + S[i]; wird doch bei S = 'hallo' 5 mal ausgeführt, wobei i von 0 bis fünf steigt,
dann wird also der erste buschstabe an die letzte zeile im memo angehängt, der nächste buchstabe auch etc... wo is das problem??
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 21:10 
Nein von 0 -5 wären 6 mal! Der höchste Index ist aber 5 also count-1

dafür muß es aber in zeile 9
ausblenden Delphi-Quelltext
1:
for i:=1 to length(S) do					

weil bei Strings auf 0 die Länge steht.

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 21:15 
was hat das jetzt mit count zu tun? und so gehts au nit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
    for i:=0 to length(S)-1 do
    begin
      RichEdit.Lines[RichEdit.Lines.Count] := RichEdit.Lines[RichEdit.Lines.Count] + S[i];
    end;
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 18.06.06 21:16 
fangen strings nicht bei 1 an? also 1 to 5 ?

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 21:16 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=1 to length(S) do
    begin
      RichEdit.Lines[RichEdit.Lines.Count-1] := RichEdit.Lines[RichEdit.Lines.Count-1] + S[i];
    end;

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 21:22 
so passiert erstmal gar nix, ergebnis = ''
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: So 18.06.06 21:27 
bei mir funzt es
testprocedure:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var
  s: String;
  i: integer;
begin
  s := 'hallo';
for i := 1 to 5 do 
  richedit1.Lines[richedit1.Lines.Count-1] := richedit1.Lines[richedit1.Lines.Count-1] + s[i]

end;

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 21:38 
aber ich wills doch in eine neue zeile ganz am ende aufnehmen dann kann ich doch kein count-1 machen, aber theoretisch muss es doch auch ohne -1 gehen ich versteh einfach nit was das miteinander zu tun hat
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 21:42 
Wie gesagt, die letzte Zeile hat den Index Count-1.
Zitat:
aber ich wills doch in eine neue zeile ganz am ende aufnehmen
Das erreichst du aber nicht, wenn du den index erhöhst. Dafür gibt es die Methoden .Lines.Add() bzw..Lines.Append()

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 21:47 
lines.add will ich aber aus dem grund nicht verwenden, weil ich doch buchstabe für buchstabe adden will
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 21:50 
Du kannst ja vor der Schleife ein Append mit Leerstring machen, dann ist Count-1 die neue Zeile.

_________________
Markus Kinzler.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: So 18.06.06 22:25 
cool danke des funzt... verweise auch auf neuen (ähnlichen) beitrag in RichEdit ähnliche kompo... in VCL thread