Autor Beitrag
MisterBum83
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 245
Erhaltene Danke: 2

WIN XP
Delphi 6
BeitragVerfasst: Mi 27.09.06 21:09 
Hallo,
ich habe 5 Edits mit Werten. Nun möchte ich diese nach den Werten eine Rangfolge verpassen, d.h. in nebenstehende Edits die Rangfolge des Wertes reinschreiben.

Hat jemand ne Idee, wie ich das bewältigen kann. Meine bisherigen Ergebnisse funzen nur teilweise...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 27.09.06 21:38 
Moin!

user profile iconMisterBum83 hat folgendes geschrieben:
ich habe 5 Edits mit Werten.

Was sind denn "Werte"? :gruebel: Zahlen, Texte, ... :nixweiss:

user profile iconMisterBum83 hat folgendes geschrieben:
Nun möchte ich diese nach den Werten eine Rangfolge verpassen, d.h. in nebenstehende Edits die Rangfolge des Wertes reinschreiben.

Mach mal ein Beispiel. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
MisterBum83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 245
Erhaltene Danke: 2

WIN XP
Delphi 6
BeitragVerfasst: Do 28.09.06 08:46 
Mit Werte meine ich Zahlen, sorry.

Edit1 Edit6
Edit2 Edit7
Edit3 Edit8
Edit4 Edit9
Edit5 Edit10

In Edit 1-5 stehen jeweils eine Zahl drin. Nun sollen diese jeweils eine Position erhalten, z.B 1. oder 2. etc. und das soll dann in Edit6-10 jeweils stehen.
jsfrigo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

win xp, Win7
D2010
BeitragVerfasst: Do 28.09.06 08:49 
Die Sortierung sollte mit einem einfachen Bubblesort funktionieren.
Einfach mal hier nach Bubblesort suchen.Da gibts bestimmt genug einträge.
Gruss
Jörg
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.09.06 09:02 
Moin!

Wie sehen denn deine bisherigen Ansätze aus, zeig doch mal etwas Code. ;) Sonst schreiben wir ja dein Programm... :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Do 28.09.06 10:43 
Wenn Du nicht selber sortieren willst, kannst Du auch eine sortierte Stringliste nehmen:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var SL : TStringList;
    i : Integer;
begin
  SL := TStringList.Create;
  SL.Sorted := True;
  for i := 1 to 5 do
    SL.Add((FindComponent('Edit' +IntTostr(i)) as TEdit).Text);
  for i := 1 to 5 do
   (FindComponent('Edit' + Inttostr(i +5)) as Tedit).Text := SL[i-1];
  SL.Free;




CU
Chris

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.09.06 11:02 
Moin!

@user profile iconchrisw: Die Stringliste sortiert aber nach Text, das ist bei Zahlen natürlich nicht korrekt. ;)

@user profile iconMisterBum83: Sollte das Ergebnis so aussehen, wie im Anhang?

cu
Narses
Einloggen, um Attachments anzusehen!
_________________
There are 10 types of people - those who understand binary and those who don´t.
MisterBum83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 245
Erhaltene Danke: 2

WIN XP
Delphi 6
BeitragVerfasst: Do 28.09.06 11:19 
user profile iconNarses hat folgendes geschrieben:
Moin!

@user profile iconMisterBum83: Sollte das Ergebnis so aussehen, wie im Anhang?

cu
Narses


Jo, genau so soll das ganze aussehen! Super! Wie hast du es gelöst???
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.09.06 11:27 
Moin!

user profile iconMisterBum83 hat folgendes geschrieben:
Wie hast du es gelöst???

- die Texte aus Edit1-5 in Edit6-10 kopieren
- Edit6.Tag := 6; Edit7.Tag := 7; etc...
- Edit6-10 sortieren (Verfahren egal, ich hab mal BubbleSort genommen)
- Wichtig: beim Sortieren Edit6-10.Text und .Tag mittauschen!
- in einem Nachgang mit einer Schleife von 1..5 die Edits6-10 durchgehen und in das Edit, auf das der .Tag des aktuell bearbeiteten zeigt, den Schleifenindex schreiben

Fertig. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
MisterBum83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 245
Erhaltene Danke: 2

WIN XP
Delphi 6
BeitragVerfasst: Do 28.09.06 11:35 
user profile iconNarses hat folgendes geschrieben:
Moin!

user profile iconMisterBum83 hat folgendes geschrieben:
Wie hast du es gelöst???

- Edit6-10 sortieren (Verfahren egal, ich hab mal BubbleSort genommen)


Hast du vielleicht gerade den Quellcode, wie ich den BubbleSort auf Edits anwende???
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.09.06 11:40 
Moin!

Probier das mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    ...
    Edit10: TEdit;
[...]
  public
    Edit: Array[0..9] of TEdit;

[...]
procedure TForm1.FormCreate(Sender: TObject);
[...]
  for i := 0 to 9 do
    Edit[i] := TEdit(FindComponent('Edit'+IntToStr(i+1)));

[...]
procedure TForm1.Button2Click(Sender: TObject);
[...]
  for i := 3 downto 0 do
    for j := 0 to i do
      if (StrToIntDef(Edit[j+5].Text,0) < StrToIntDef(Edit[j+6].Text,0)) then begin
        stmp := Edit[j+5].Text;
        Edit[j+5].Text := Edit[j+6].Text;
        Edit[j+6].Text := stmp;
        itmp := Edit[j+5].Tag;
        Edit[j+5].Tag := Edit[j+6].Tag;
        Edit[j+6].Tag := itmp;
      end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
MisterBum83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 245
Erhaltene Danke: 2

WIN XP
Delphi 6
BeitragVerfasst: Do 28.09.06 13:42 
Danke an alle, hat funktioniert!!!

Besonderen Dank an Narses ;-)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.09.06 13:51 
Moin!

Fein, dann hier mein kompletter Quelltext als Referenz: ;)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
procedure TForm1.FormCreate(Sender: TObject);
  var
    i: Integer;
begin
  Randomize;
  for i := 0 to 9 do
    Edit[i] := TEdit(FindComponent('Edit'+IntToStr(i+1)));
  Button1Click(Self);
end;

procedure TForm1.Button1Click(Sender: TObject);
  var
    i: Integer;
begin
  for i := 0 to 4 do begin
    Edit[i].Text := IntToStr(Random(100));
    Edit[i+5].Text := '?';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
  var
    i,j,itmp: Integer;
    stmp: String;
begin
  for i := 0 to 4 do begin
    Edit[i+5].Text := Edit[i].Text;
    Edit[i+5].Tag := i+5;
  end;
  for i := 3 downto 0 do
    for j := 0 to i do
      if (StrToIntDef(Edit[j+5].Text,0) < StrToIntDef(Edit[j+6].Text,0)) then begin
        stmp := Edit[j+5].Text;
        Edit[j+5].Text := Edit[j+6].Text;
        Edit[j+6].Text := stmp;
        itmp := Edit[j+5].Tag;
        Edit[j+5].Tag := Edit[j+6].Tag;
        Edit[j+6].Tag := itmp;
      end;
  for i := 1 to 5 do
    Edit[Edit[i+4].Tag].Text := IntToStr(i);
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.