| Autor |
Beitrag |
hansdergott
      
Beiträge: 55
XP Mediacenter Edition; XP Home
Delphi
|
Verfasst: So 23.03.08 03:24
hallo zusammen
wie mache ich aus einem text den ich aus einer listbox habe
wieder mauskoordinaten?
der text sieht folgener maßen aus zb. 133;762 oder 53,123
wie kann eine procedure ausehen damit sie auch erkennt das die 1. zahl
zb nur eine stelle und die andere zb 3 stellen hatt
die erste zahl ist immer x und die 2. ist immer y
dank euch im voraus
ps : wer rechtschreibfehler findet wird erschossen 
|
|
CarpeDiem
      
Beiträge: 128
WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
|
Verfasst: So 23.03.08 07:05
Hallo,
probiers mal so:
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| AnsiString sLinks = ""; AnsiString sRechts = ""; for (int i = 0; i < ListBox1->Count; i++) { for (int j = 1; j <= ListBox1->Items->Strings[i].Length(); j++) { if (MidStr(ListBox1->Items->Strings[i],j,1) == ",") { sLinks = MidStr(ListBox1->Items->Strings[i],1,(j-1)); sRechts = MidStr(ListBox1->Items->Strings[i],(j+1),(ListBox1->Items->Strings[i].Length()-1)); break; } } } | sLinks ist dann der linke Wert und sRechts der rechte Wert vom Komma. Bei Dir ist dann sLinks = x, sRechts = y. Die Länge findest Du heraus mit DeinString.Length(). Der Quellcode ist denk ich mal ansonsten selbsterklärend, auch wenn er in C++ geschrieben ist, musst halt umschreiben. Außerdem musst Du noch mit #include "StrUtils.hpp" die StrUtils einbinden(wegen MidStr()).
_________________ Stefan - Carpe Diem
Es ist keine Schande zu fallen, eine Schande ist nur nicht wieder aufzustehen
|
|
Yogu
      
Beiträge: 2598
Erhaltene Danke: 156
Ubuntu 13.04, Win 7
C# (VS 2013)
|
Verfasst: So 23.03.08 12:28
Das war C#. Wir sind hier im Delphi-Forum
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| var sLinks, sRechts: String; i, j: Integer; Cursors: array of TPoint;
sLinks := ''; sRechts := ''; SetLength(Cursors, 0); for i := 0 to ListBox1.Count-1 do begin for j := 1 to Length(ListBox1.Items[i]) do begin if ListBox1.Items.[i][j] in [',', ';'] then begin sLinks := Copy(ListBox1.Items[i], 1, j-1); sRechts := Copy(ListBox1.Items[i], j+1, Length(ListBox1.Items[i]-1); Break; end; end; SetLength(Cursors, Length(Cursors)+1); Cursors[Length(Cursors)-1] := Point(StrToInt(sLinks), StrToInt(sRechts)); end; |
Units oder so wie in C# brauchst du da keine zusätzlichen - funktioniert mit den standardmäßig eingebundenen.
Am Schluss hast du ein dynamisches Array Cursors, welche als Punkte die Mauspositionen enthalten. Die Anzahl bekommst du über Length(Cursors) raus. Pass aber auf, dass wirklich nur Strings in diesem Format enthalten sind, sonst brauchst du noch eine Fehlerbehandlung.
|
|
Hidden
      
Beiträge: 2242
Erhaltene Danke: 55
Win10
VS Code, Delphi 2010 Prof.
|
Verfasst: So 23.03.08 13:46
Hi,
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| var sLinks, sRechts: String; i, j: Integer; Cursors: array of TPoint;
sLinks := ''; sRechts := ''; SetLength(Cursors, 0); for i := 0 to ListBox1.Count-1 do begin for j := 1 to Length(ListBox1.Items[i]) do begin if ListBox1.Items.[i][j] in [',', ';'] then begin sLinks := Copy(ListBox1.Items[i], 1, j-1); sRechts := Copy(ListBox1.Items[i], j+1, Length(ListBox1.Items[i]) - 1); Break; end; end; SetLength(Cursors, Length(Cursors)+1); Cursors[High(Cursors)] := Point(StrToInt(sLinks), StrToInt(sRechts)); end; |
Du wirst nachlässig, alter Meister
Edit: nagels Klammer hinzugrfügt 
_________________ Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Zuletzt bearbeitet von Hidden am So 23.03.08 14:20, insgesamt 1-mal bearbeitet
|
|
nagel
      
Beiträge: 708
Win7, Ubuntu 10.10
|
Verfasst: So 23.03.08 13:59
In Zeile 13 fehlt noch eine schließende Klammer am Ende.
|
|
hansdergott 
      
Beiträge: 55
XP Mediacenter Edition; XP Home
Delphi
|
Verfasst: So 23.03.08 15:21
Titel: re
hallo zusammen
besten dank für den quellcode
werds gleich mal versuchen
gruß hans
|
|
Yogu
      
Beiträge: 2598
Erhaltene Danke: 156
Ubuntu 13.04, Win 7
C# (VS 2013)
|
Verfasst: So 23.03.08 20:30
Hidden hat folgendes geschrieben: | Du wirst nachlässig, alter Meister  |
Sorry, ich habs "On-The-Fly" übersetzt...
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Mo 24.03.08 15:10
Warum so kompliziert?
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| Function StrToPoint(S : String): TPoint; var P: Integer; begin Result := Point(-1, -1); P := Pos(';', S); If P < 1 Then P := Pos(',', S); If P < 1 Then Exit; Result := Point(StrToIntDef(Copy(S, 1, P - 1), -1), StrToIntDef(Copy(S, P, MaxInt), -1)); end; |
Sogar mit Fehlerprüfung?
_________________ 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.
|
|
|