Autor Beitrag
sagar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 05.08.07 12:18 
HAllo!
Ich habe folgendes Problem: ICh habe in einem Memo mittels Pos('Test', memo1.lines.text) einen String gesucht und erhalte dann die Position zurück. Wie finde ich heraus, welche Line das ist ?

mfg
sagar
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 05.08.07 12:21 
Anzahl des Teilstrings #13#10 vor deiner Fundstelle zählen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sagar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 05.08.07 12:24 
ERst einmal danke für deine Antwort.
Wie mache ich das ? Gibt es dafür eine Methode oder muss ich jedes Zeichen mittels einer Schleife durchgehen und auf #13#10 überprüfen ?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 05.08.07 12:32 
Es gibt eine zweite Funktion PosEx, mit der man ab einem bestimmten Offset in einem String suchen kann.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
sagar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 05.08.07 12:57 
Hab folgendes Probiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
i:integer;
AnzahlZeilenumbr:integer;
begin
AnzahlZeilenumbr:=0;
  for i:=0 to position do
    begin
    if memo.lines.Text[i] = #13#10 then AnzahlZeilenumbr:=AnzahlZeilenumbr+1;
    end;

result:= AnzahlZeilenumbr;
end;


funktioniert leider nicht.

position wird übrigens beim Methodenaufruf mit übergeben.

Moderiert von user profile iconGausi: List- durch Delphi-Tags ersetzt
Moderiert von user profile iconGausi: Beiträge zusammengefasst.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 05.08.07 14:20 
Warum nicht einfach:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var
    L: Integer;
    P, P2: Integer;
    S: String;
    M: String;
begin
    S := 'DeinText';
    M := Memo1.Lines.Text;
    L := -1;
    P := 0;
    P2 := Pos(S, M);
    While P < P2 Do
    Begin
        Inc(L);
        P := PosEx(#13#10, M, P);
        If P = 0 Then P := Length(M);
    End;
    Result := L;
end;


Ungetestet, sollte aber funzen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 05.08.07 17:59 
Wenn du die Position gar nicht brauchst, sondern nur die Zeile, dann kannst du auch mit einer Schleife jede Zeile des Memos durchgehen und dann Pos nur auf die Zeile anwenden. Wenn der Rückgabewert von Pos > 0 ist, dann wurde der gesuchte String gefunden.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 05.08.07 20:51 
:lol: :lol: :lol: :lol: :lol:
Ähh, was soll denn das werden? (Ich meine jetzt die Antworten ;-).) Es gibt ja schließlich die Möglichkeit, dies direkt zu erfragen^^.
ausblenden Delphi-Quelltext
1:
AnzahlZeilenumbr := SendMessage(memo.Handle, EM_LINEFROMCHAR, position, 0);					

bzw.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function GetMemoLine(uMemo: TMemo; uPosition: Integer): Integer;
begin
  Result := SendMessage(uMemo.Handle, EM_LINEFROMCHAR, uPosition, 0);
end;

Warum dein Quelltext nicht funktioniert: if memo.lines.Text[i] = #13#10
#13#10 sind aber ZWEI Zeichen...