Autor Beitrag
sacharja
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 19:02 
Hallo zusammen,
ich möchte den Inhalt einer Memo Zeile überprüfen, bekomme aber immer einen Fehler. Das ist mein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
var i:integer; Memobox: string;
begin
if SaveDialog1.Execute then
  begin
  for i:=0 to Memo1.Lines.count do
    begin
    Memobox:=Memo1.Lines[i];
    if Memobox.Text='asdf' then
    Memobox[i]:='<a href="'+Memobox+'">'+Memobox+'</a>';
    end;
  Memo1.lines.Savetofile(SaveDialog1.FileName);
  end
end;



Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Mi 01.02.2006 um 19:05
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 01.02.06 19:05 
Hallo!

Die Zeilen eines Memos sind von 0 bis Anzahl-1 durchnummeriert. Deine Schleife läuft aber bis Memo1.Lines.count, also eins zu weit. Das wird einen entsprechenden Fehler produzieren. Es ist übrigens immer von Vorteil, hier den Fehler zu posten, der gemeldet wird. :-)

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 01.02.06 19:18 
ausblenden Delphi-Quelltext
1:
Memobox.Text					

ein string hat keine eigenschaft text ;)
sacharja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 20:02 
Danke für die Antworten, ich habe den Code entsprechend angepasst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);   
var i:integer; Memobox: string;
begin
if SaveDialog1.Execute then
  begin
  for i:=0 to Memo1.Lines.count-1 do
    begin
    Memobox:=Memo1.Lines[i];
    if not Memobox='asdf' then
    Memobox[i]:='<a href="'+Memobox+'">'+Memobox+'</a>';
    end;
  Memo1.lines.Savetofile(SaveDialog1.FileName);
  end
end;


Aber immer noch der Fehler am Anfang der if Schleife "[Error] Unit1.pas(37): Operator not applicable to this operand type". Schreibe ich statt "if not" nur "if" kommt nur noch der Fehler innerhalb der Schleife "[Error] Unit1.pas(38): Incompatible types: 'Char' and 'String'"

Was läuft da schief?
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 01.02.06 20:10 
mama so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);   
var 
  i: integer; 
  Memobox: string;
begin
  if SaveDialog1.Execute then
  begin
    for i := 0 to Memo1.Lines.count - 1 do
    begin
      Memobox := Memo1.Lines[i];
      if Memobox <> 'asdf' then
        Memobox := '<a href="' + Memobox + '">' + Memobox + '</a>';
      Memo1.lines[i] := Memobox;
    end;
    Memo1.lines.Savetofile(SaveDialog1.FileName);
  end
end;
sacharja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 20:35 
Ein Fehler taucht jetzt nicht mehr auf, aber bei "if Memobox <> 'asdf' then" würde er bei einer Zeile die "asdff" heißt trotzdem den Schleifeninhalt ausführen.

Mein 2. Versuch daher "if Memobox.IndexOfName('<a')=-1 then", aber auch hier wieder der bekannte Fehler "[Error] Unit1.pas(39): Record, object or class type required" :?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 02.02.06 13:45 
user profile iconsacharja hat folgendes geschrieben:
Ein Fehler taucht jetzt nicht mehr auf, aber bei "if Memobox <> 'asdf' then" würde er bei einer Zeile die "asdff" heißt trotzdem den Schleifeninhalt ausführen.
Mach dich über die Delphi-Hilfe mal schlau, was die Funktion pos so machen kann.

_________________
We are, we were and will not be.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 02.02.06 15:59 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);   
var 
  i: integer; 
  Memobox: string;
begin
  if SaveDialog1.Execute then
  begin
    for i := 0 to Memo1.Lines.count - 1 do
    begin
      Memobox := Memo1.Lines[i];
      if pos('asdf', Memobox) <> 0 then
        Memobox := '<a href="' + Memobox + '">' + Memobox + '</a>';
      Memo1.lines[i] := Memobox;
    end;
    Memo1.lines.Savetofile(SaveDialog1.FileName);
  end
end;

sollte gehen, ich weiß dann aber net, ob die nächste zeile sinn macht, was hast du denn eigentlich vor ?
sacharja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 02.02.06 18:18 
Danke für den guten Tipp mit Pos.

Ich habe es so verbessert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
    for i := 0 to Memo1.Lines.count - 1 do
    begin
      Memobox := Memo1.Lines[i];
      if pos('<a',Memobox) = 0 then
        Memobox := '<a href="' + Memobox + '">' + Memobox + '</a><br>';
    end;


Zitat:
was hast du denn eigentlich vor ?

Ich möchte eigentlich nur jede Zeile im Memo überprüfen, ob sie ein "<a" enthält und wenn nicht möchte ich sie zeile durch einen Link ersetzen (der als Ziel den vorherigen Zeileninhalt hat). Leider ersetzt er jetzt aber nichts :?
sacharja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 03.02.06 11:21 
Hat sich geklärt. Habe da was mit JS durcheinander gebracht. Danke für eure Hilfe.


ausblenden Delphi-Quelltext
1:
2:
if pos('<a',Memobox) = 0 then   
        Memo1.Lines[i] := '<a href="' + Memobox + '">' + Memobox + '</a><br>';