以下是 TListView.CustomSort 的使用例 function CustomQuickSort(Item1, Item2: TListItem; Data: Integer): integer; stdcall; var Str1, Str2: string; I,J,K,L:Integer; begin try if Data = -1 then begin Str1 := Item1.Caption; Str2 := Item2.Caption; end else begin Str1 := Item1.SubItems[Data]; Str2 := Item2.SubItems[Data]; end; J := Length(Str1); K := Length(Str2); if J < K then begin L := K - J; L := L - 1; for I := 0 to L do Str1 := '0' + Str1; end else begin L := J - K; L := L - 1; for I := 0 to L do Str2 := '0' + Str2; end; Result := AnsiCompareStr(Str1, Str2); Result := 1 * Result; // Set direction flag. except Result := 0; // If errors, say they are equal. end; end;