Autor Beitrag
Force
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Di 15.08.06 12:11 
Hi!

Ich hab vor kurzem folgenden Code zum Ordnen von TListViews gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
var
  ix: Integer;
begin
  if ColumnToSort = 0 then
  begin
    if SortDir = 0 then
      Compare := CompareText(Item1.Caption,Item2.Caption)
    else
      Compare := CompareText(Item2.Caption,Item1.Caption);
  end //if ColumnToSort = 0 then
  else
  begin
   ix := ColumnToSort - 1;
   if SortDir = 0 then
     Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix])
   else
     Compare := CompareText(Item2.SubItems[ix],Item1.SubItems[ix]);
  end; //if ColumnToSort <> 0 then
end;


Immer wenn ein Item der TListview hinzugefügt wird, wird es auch einer TStringList hinzugefügt. Nun möchte ich aber, dass die TStringlist dann auch so geordnet wird, dass jeder String der selben ID zugewiesen ist, der auch in der TListView das dazugehörige Item zugewiesen ist...

Könnt ihr mir dabei helfen, wie ich das machen soll?

Danke,

Force
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 15.08.06 12:18 
Moin!

Pack in die .Data-Eigenschaft der ListView-Items den Index in die Stringliste, dann brauchst du die Liste nicht sortieren (was auch überflüssig ist).

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Di 15.08.06 15:01 
Hi, ich hab mir jetzt zwar mehrere Tuts über Pointer durchgelesen., allerdings verstehe ich immer noch nicht, wie ich das jetzt machen soll...

Gibt es noch eine andere Methode?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 15.08.06 15:33 
Moin!

Du sollst da ja auch keinen Pointer rein tun, sondern einen Integer "als Pointer getarnt" (Typecast), das ist dann der Index in die Stringliste. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Di 15.08.06 15:36 
uff, natürlich ^^

Danke :D



/Edi8t: Wie kann man eigentlich einen pointer in einen integer umwandeln?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 15.08.06 15:59 
Moin!

IntVar := Integer(PointerVar); ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Di 15.08.06 16:00 
ja, hab ich eben auch gesehen, tut mir leid, ich hab vergessen das edit zu löschen...