Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 10:16 
Hallo,

ich finde es etwas unübersichtilich, wenn im ListView Dateien und Ordner total vermischt sind, deshalb wollte ich das immer einzeln sortieren lassen... bei jeder sortierung immer oben die Ordner und unten die dateien...
Wie kann ich sowas machen?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 10:25 
Moin!

Wenn du das mit der .Data-Eigenschaft machst: betrachte den Wert als Cardinal, pack die ersten 4 Bytes des Namens rein und setz Bit31, dann haste das automatisch so. ;) (OK, sortiert dann nur nach den ersten 4 Zeichen des Namens, sollte aber doch reichen, oder?)

cu
Narses

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


Zuletzt bearbeitet von Narses am Fr 27.07.07 10:27, insgesamt 2-mal bearbeitet
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 10:26 
äh...
wiebitte?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 10:42 
Moin!

Vergiss das da oben... :?

Mach für die gefundenen Files/Ordner ein entsprechendes Objekt in einer TObjectList und pack in die .Data-Eigenschaft eine Referenz auf das Objekt. In der ListView-Sortiermethode kannst du dann die 4 Fälle unterscheiden:
1. Ordner:Ordner -> Namen vergleichen
2. Ordner:Datei -> fix: Ordner ist kleiner
3. Datei:Ordner -> fix: Ordner ist größer
4. Datei:Datei -> Name und Größe vergleichen
:idea:

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 10:53 
Mir fällt ghrad so ein... kann man das nicht auch über Vererbung machen?
also ungefähr so:
ausblenden Delphi-Quelltext
1:
2:
3:
type TMyListItem = class(TListItem)
  Dir: Boolean;
end;

Und das dann abfragen...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 10:57 
Moin!

Hm, auch eine Idee. :zustimm: Probier´s doch mal aus. ;)

cu
Narses

PS: Rückmeldung erbeten! :)

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 11:04 
nur wie kann ich das so einbinden, dass bei ListView1.Items.Add ein TMyListItem anstatt ein TListItem erstellt wird?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 11:08 
Moin!

Gar nicht, du mußt das Item selbst erstellen und mit .AddItem übergeben. ;)

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 11:13 
okay...
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 11:48 
Wenn ich
ListView1.AddItem(liNew.Caption, liNew); angebe, bekomme ich nur die erste Spalte
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 12:41 
Moin!

Getestet: ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
type
  TMyListItem = class(TListItem)
  private
    FTest: Boolean;
  public
    property Test: Boolean read FTest write FTest;
  end;

procedure TForm1.Button2Click(Sender: TObject);
  var
    MyListItem: TMyListItem;
begin
  MyListItem := TMyListItem.Create(ListView1.Items);
  MyListItem.Test := (Random(2) = 0);
  MyListItem.SubItems.Add(BoolToStr(MyListItem.Test));
  ListView1.Items.AddItem(MyListItem);
  MyListItem.Caption := IntToStr(ListView1.Items.Count);
end;

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 13:24 
Aber ich kann dann im OnCompare kein Item1.Dir und auch kein Item2.Dir verwenden
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 13:33 
Moin!

Doch, du mußt einen Typecast auf deinen Typ machen (ist es ja auch, weiß aber das ListView nicht). ;)

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 13:35 
Dummes ListView... naja jetzt läufts, aber leider noch nicht, wenn das verändert wird, also wenn man den Ordner wechselt, dann soll es auch schon sortiert werden... Wie kann ich das machen?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 13:43 
user profile iconWolle92 hat folgendes geschrieben:
äh...
wiebitte?

;)

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 15:31 
soll das jetzt ne gegenfrage sein? als zitat getarnt? oder einfach nur deine meinung zu dem Post?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 16:36 
Moin!

user profile iconWolle92 hat folgendes geschrieben:
soll das jetzt ne gegenfrage sein? als zitat getarnt?

Jup, scheint nicht witzig zu sein... :?

OK, Langform: ich verstehe das Problem nicht. :)

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 16:45 
das problem ist, dass beim start, oder wenn man das Verzeichnis wechselt, die Sortierung nicht auf Ordner aufgeteilt funktioniert...
Und das will ich ändern
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.07.07 16:47 
Moin!

Wenn ein ListView1.AlphaSort; das Problem nicht behebt, dann wirst du wohl erstmal die Ursache dafür finden müssen - oder Code zeigen. :nixweiss:

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 27.07.07 17:13 
Okay, habs jetzt alles gebacken gekriegt, auch ohne ofen...
Gibt zwar noch nen paar Bugs wegen der Reihenfolge, aber für die entwicklung reichts

Und die Sortierung für Ordner und Dateien muss man ja nur beim Namen machen, Größe und Dateityp gehen ja automatisch