Autor Beitrag
hansdergott
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 55

XP Mediacenter Edition; XP Home
Delphi
BeitragVerfasst: 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 :-D
CarpeDiem
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 128

WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
BeitragVerfasst: So 23.03.08 07:05 
Hallo,

probiers mal so:
ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 23.03.08 12:28 
Das war C#. Wir sind hier im Delphi-Forum :mrgreen:

ausblenden 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); // Cursor-Array nullsetzen

for i := 0 to ListBox1.Count-1 do // Alle Einträge abklappern
begin
  for j := 1 to Length(ListBox1.Items[i]) do // Alle Zeichen abkalppern
  begin
    if ListBox1.Items.[i][j] in [',', ';'] then // Nach , und ; suchen
    begin
      sLinks := Copy(ListBox1.Items[i], 1, j-1); // Links-String berechnen
      sRechts := Copy(ListBox1.Items[i], j+1, Length(ListBox1.Items[i]-1); // Rechts-String berechnen
      Break;
    end;
  end;
  SetLength(Cursors, Length(Cursors)+1); // Cursor-Array um ein Element erweitern
  Cursors[Length(Cursors)-1] := Point(StrToInt(sLinks), StrToInt(sRechts)); // Strings zu Integers umwandeln und als Point dem Cursor-Array zuweisen
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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 23.03.08 13:46 
Hi,

ausblenden 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); // Cursor-Array nullsetzen
for i := 0 to ListBox1.Count-1 do // Alle Einträge abklappern
begin
  for j := 1 to Length(ListBox1.Items[i]) do // Alle Zeichen abkalppern
  begin
    if ListBox1.Items.[i][j] in [',', ';'] then // Nach , und ; suchen
    begin
      sLinks := Copy(ListBox1.Items[i], 1, j-1); // Links-String berechnen
      sRechts := Copy(ListBox1.Items[i], j+1, Length(ListBox1.Items[i]) - 1); // Rechts-String berechnen
      Break;
    end;
  end;
  SetLength(Cursors, Length(Cursors)+1); // Cursor-Array um ein Element erweitern
  Cursors[High(Cursors)] := Point(StrToInt(sLinks), StrToInt(sRechts)); // Strings zu Integers umwandeln und als Point dem Cursor-Array zuweisen
end;


Du wirst nachlässig, alter Meister :mrgreen:

Edit: user profile iconnagels Klammer hinzugrfügt :D

_________________
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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 23.03.08 13:59 
In Zeile 13 fehlt noch eine schließende Klammer am Ende.
hansdergott Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 55

XP Mediacenter Edition; XP Home
Delphi
BeitragVerfasst: So 23.03.08 15:21 
Titel: re
hallo zusammen

besten dank für den quellcode
werds gleich mal versuchen

gruß hans
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 23.03.08 20:30 
user profile iconHidden hat folgendes geschrieben:
Du wirst nachlässig, alter Meister :mrgreen:

Sorry, ich habs "On-The-Fly" übersetzt...
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: Mo 24.03.08 15:10 
Warum so kompliziert?

ausblenden 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.