こんにちは。
> TStringGrid の列ソートで、列をListBoxにいれて、
> Sortし、元に戻すということをしています。
ListBox ではなく、StringList を使うといいですよ。
function CustomSortASC(List: TStringList; Index1, Index2: Integer): Integer;
// 昇順ソート
begin
//result := AnsiCompareStr(List[Index1], List[Index2]); // ロケール考慮/大文字小文字区別
result := CompareStr(List[Index1], List[Index2]); // ロケール無視/大文字小文字区別
//result := AnsiCompareText(List[Index1], List[Index2]); // ロケール考慮/大文字小文字無視
//result := CompareText(List[Index1], List[Index2]); // ロケール無視/大文字小文字無視
end;
function CustomSortDESC(List: TStringList; Index1, Index2: Integer): Integer;
// 降順ソート
begin
//result := -AnsiCompareStr(List[Index1], List[Index2]); // ロケール考慮/大文字小文字区別
result := -CompareStr(List[Index1], List[Index2]); // ロケール無視/大文字小文字区別
//result := -AnsiCompareText(List[Index1], List[Index2]); // ロケール考慮/大文字小文字無視
//result := -CompareText(List[Index1], List[Index2]); // ロケール無視/大文字小文字無視
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SL: TStringList;
begin
SL := TStringList.Create;
try
SL.Add('しばだ あきこ');
SL.Add('しばた たみこ');
SL.Add('しばだ ようこ');
SL.CustomSort(CustomSortASC ); // 昇順ソート
// SL.CustomSort(CustomSortDESC); // 降順ソート
Memo1.Lines.Text := SL.Text;
finally
SL.Free;
end;
end;
Delphi のコードで申し訳ありませんが (w
--
by DEKO
-------------------------------------
http://homepage1.nifty.com/ht_deko/
ht_...@nifty.com
-------------------------------------
MLホームページ:
http://www.freeml.com/delphi-users
----------------------------------------------------------------------
写メはMLにアップしてみんなと楽しもう!
http://ad.freeml.com/cgi-bin/sa.cgi?id=fwyxQ