Autor Beitrag
SweeT_C
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 21.03.07 17:54 
Moin, moin,

ich suche nach einer möglichkeite eine komplette Zeile zB in einem memofeld zu löschen. Alelrdings kenne ich nur den Anfang der Zeile, die position ist unbekannt.

Wie kann ich das realisieren ?

MfG n Thx
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 21.03.07 17:58 
Dann arbeitest du innerhalb einer for-Schleife mit Copy. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i := memo1.lines.count - 1 downto 0 do
begin
  if (Copy(memo1.lines[i],0,anzahl_zeichen) = 'mein bekannter Anfang') then
    memo1.lines.delete(i);
end;

So in etwa. :P Du musst bedenken, dass bei dieser Variante dann alle Zeilen gelöscht werden, die den Anfang haben.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot


Zuletzt bearbeitet von Marco D. am Mi 21.03.07 20:12, insgesamt 1-mal bearbeitet
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 21.03.07 18:02 
user profile iconMarco D. hat folgendes geschrieben:
Dann arbeitest du innerhalb einer for-Schleife mit Copy. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i := to memo1.lines.count - 1 downto 0 do
begin
  if (Copy(memo1.lines[i],0,anzahl_zeichen) = 'mein bekannter Anfang') then
    memo1.lines.delete(i);
end;
...

Das wird sicherlich eine Exception ergeben, Du musst eine while-Schleife verwenden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
I := 0;
while I<Memo1.Lines.Count do
  if (Copy(memo1.lines[i],0,anzahl_zeichen) = 'mein bekannter Anfang') then
    memo1.lines.delete(i)
  else Inc(I);
end;

oder per Pos
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
I := 0;
while I<Memo1.Lines.Count do
  if Pos(Anfangstext,Memo1.Lines[I])=1 
    then
      Memo1.Lines.Delete(I)
    else 
      Inc(I);
end;

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 21.03.07 18:02 
Hallo!

Du brauchst Pos() und memo.lines.delete(Zeilennummer)

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
SweeT_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mi 21.03.07 18:11 
Danke an alle, jetzt funktioniert es :) !
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 21.03.07 18:13 
@Kroko: Warum gibt das eine Exception?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Mi 21.03.07 20:09 
user profile iconMarco D. hat folgendes geschrieben:
@Kroko: Warum gibt das eine Exception?

Versteh ich auch net. Meine Glaskugel sagt aber, dass Kroko das downto entgangen ist(wahrscheinlich weil komischerweise zusätzlich noch n to drin steht)...

Zum Thema siehe auch: r2c2.weingut-rehn.de...itung_mit_Delphi.htm

mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 21.03.07 20:14 
user profile iconr2c2 hat folgendes geschrieben:
komischerweise zusätzlich noch n to drin steht)...

WO? :mrgreen:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Mi 21.03.07 20:15 
user profile iconKroko hat folgendes geschrieben:
user profile iconMarco D. hat folgendes geschrieben:
Dann arbeitest du innerhalb einer for-Schleife mit Copy. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i := to memo1.lines.count - 1 downto 0 do
begin
  if (Copy(memo1.lines[i],0,anzahl_zeichen) = 'mein bekannter Anfang') then
    memo1.lines.delete(i);
end;
...



mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 21.03.07 23:43 
Hallo,

und memo1.lines[i] ist ein String,
ausblenden Delphi-Quelltext
1:
(Copy(memo1.lines[i],0,anzahl_zeichen)					

und beginnt mit Index 1.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )