|
begin process at 2008 07 05 05:44:53
Derniers logiciels
|
Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
TRI DE CHIFFRE , DATE OU TEXT DANS UN TLISTVIEW
Information sur la source
Description
Exemple d'implémentation de tri dans un tlistview pour des dates, chiffres ou du texte
Source
- function CustomSortProc(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
- var date1,date2:tdatetime;
- ix:integer;
- begin
- ix :=abs(Paramsort) -1;
- if not TryStrToDate(item1.SubItems[ix],date1) then
- date1:=strtodate('01/01/1799');
-
- if not TryStrToDate(item2.SubItems[ix],date2) then
- date2:=strtodate('01/01/1799');
-
- result:=CompareDate(date1,date2);
- if paramsort<0 then result:=-result;
-
-
- end;
- function CustomSortProcTime(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
- var date1,date2:tdatetime;
- ix:integer;
- begin
- ix :=abs(Paramsort) -1;
- if not TryStrToDatetime(item1.SubItems[ix],date1) then
- date1:=strtodatetime('01/01/1799 00:00:00');
-
- if not TryStrToDatetime(item2.SubItems[ix],date2) then
- date2:=strtodatetime('01/01/1799 00:00:00');
-
- result:=CompareDatetime(date1,date2);
- if paramsort<0 then result:=-result;
-
-
- end;
-
- function CustomSortProcChif(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
- var i1,i2:integer;
- ix:integer;
- begin
- ix :=abs(Paramsort) -1;
- if not TryStrToint(item1.SubItems[ix],i1) then
- i1:=0;
-
- if not TryStrToint(item2.SubItems[ix],i2) then
- i2:=0;
-
- result:=comparevalue(i1,i2);
- if paramsort<0 then result:=-result;
-
-
- end;
-
- procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
- Data: Integer; var Compare: Integer);
- var
- ix:Integer;
- begin
- if croissant then
- if ColumnToSort =0 then
- Compare :=CompareText(Item1.Caption,Item2.Caption)
- else begin
- ix :=ColumnToSort -1;
- Compare :=CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
- end
- else
- if ColumnToSort =0 then
- Compare :=CompareText(Item2.Caption,Item1.Caption)
- else begin
- ix :=ColumnToSort -1;
- Compare :=CompareText(Item2.SubItems[ix],Item1.SubItems[ix]);
- end;
- end;
-
- procedure TForm1.ListView1ColumnClick(Sender: TObject;
- Column: TListColumn);
- begin
-
- croissant:= not croissant; //inversion du précédent ordre de tri
- ColumnToSort :=Column.Index; //Quel colonne est à trier ?
- //Ensuite on détermine quel est le type de colonne à trier:
- //on peut aussi les déterminer en spécifiant un tag particulier dans chaque colonne
- if pos('DateTime',Column.Caption)>0 then begin
- if croissant then
- (Sender as TCustomListView).CustomSort(@CustomSortProctime,column.index)
- else
- (Sender as TCustomListView).CustomSort(@CustomSortProctime,-column.index)
- end
- else
- if pos('Date',Column.Caption)>0 then begin
- if croissant then
- (Sender as TCustomListView).CustomSort(@CustomSortProc,column.index)
- else
- (Sender as TCustomListView).CustomSort(@CustomSortProc,-column.index)
- end
- else
- if pos('Chiffre',Column.Caption)>0 then begin
- if croissant then
- (Sender as TCustomListView).CustomSort(@CustomSortProcChif,column.index)
- else
- (Sender as TCustomListView).CustomSort(@CustomSortProcChif,-column.index)
- end
- else
- (Sender as TCustomListView).AlphaSort; //Méthode de comparaison de text par défaut.
-
- end;
function CustomSortProc(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
var date1,date2:tdatetime;
ix:integer;
begin
ix :=abs(Paramsort) -1;
if not TryStrToDate(item1.SubItems[ix],date1) then
date1:=strtodate('01/01/1799');
if not TryStrToDate(item2.SubItems[ix],date2) then
date2:=strtodate('01/01/1799');
result:=CompareDate(date1,date2);
if paramsort<0 then result:=-result;
end;
function CustomSortProcTime(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
var date1,date2:tdatetime;
ix:integer;
begin
ix :=abs(Paramsort) -1;
if not TryStrToDatetime(item1.SubItems[ix],date1) then
date1:=strtodatetime('01/01/1799 00:00:00');
if not TryStrToDatetime(item2.SubItems[ix],date2) then
date2:=strtodatetime('01/01/1799 00:00:00');
result:=CompareDatetime(date1,date2);
if paramsort<0 then result:=-result;
end;
function CustomSortProcChif(Item1,Item2:TListItem;ParamSort:integer):integer;stdcall;
var i1,i2:integer;
ix:integer;
begin
ix :=abs(Paramsort) -1;
if not TryStrToint(item1.SubItems[ix],i1) then
i1:=0;
if not TryStrToint(item2.SubItems[ix],i2) then
i2:=0;
result:=comparevalue(i1,i2);
if paramsort<0 then result:=-result;
end;
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
var
ix:Integer;
begin
if croissant then
if ColumnToSort =0 then
Compare :=CompareText(Item1.Caption,Item2.Caption)
else begin
ix :=ColumnToSort -1;
Compare :=CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
end
else
if ColumnToSort =0 then
Compare :=CompareText(Item2.Caption,Item1.Caption)
else begin
ix :=ColumnToSort -1;
Compare :=CompareText(Item2.SubItems[ix],Item1.SubItems[ix]);
end;
end;
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
croissant:= not croissant; //inversion du précédent ordre de tri
ColumnToSort :=Column.Index; //Quel colonne est à trier ?
//Ensuite on détermine quel est le type de colonne à trier:
//on peut aussi les déterminer en spécifiant un tag particulier dans chaque colonne
if pos('DateTime',Column.Caption)>0 then begin
if croissant then
(Sender as TCustomListView).CustomSort(@CustomSortProctime,column.index)
else
(Sender as TCustomListView).CustomSort(@CustomSortProctime,-column.index)
end
else
if pos('Date',Column.Caption)>0 then begin
if croissant then
(Sender as TCustomListView).CustomSort(@CustomSortProc,column.index)
else
(Sender as TCustomListView).CustomSort(@CustomSortProc,-column.index)
end
else
if pos('Chiffre',Column.Caption)>0 then begin
if croissant then
(Sender as TCustomListView).CustomSort(@CustomSortProcChif,column.index)
else
(Sender as TCustomListView).CustomSort(@CustomSortProcChif,-column.index)
end
else
(Sender as TCustomListView).AlphaSort; //Méthode de comparaison de text par défaut.
end;
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | 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 | | | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|
|