Function Compare(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
Result := lstrcmp(PChar(TListItem(Item1).Caption),
PChar(TListItem(Item2).Caption));end;
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ListView1.CustomSort(@Compare,0);
end;
begin
Result := lstrcmp(PChar(TListItem(Item1).Caption),
PChar(TListItem(Item2).Caption));end;
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ListView1.CustomSort(@Compare,0);
end;
解决方案 »
- 不解决问题不吃饭:DELPHI ADO+SQL SERVER 2000做的程序,客户端怎么连接有问题
- 用delphi能开发火狐的工具栏么?
- 请教调用时间控件的方法-很初级的,分不多了,大家帮帮忙,感谢
- 关于dbgrid的一个小问题(快答快结)
- 如何共享C盘??
- "一个菜鸟问题,如何判断ClientSocket连接成功?"问题已经解决了,请myling(阿德)来领分
- 如何从不确定列的Excel文件中读出数据写入到文本?-在线100分-
- 急!急!!急!!!请问高手们数学中的西格码等众多的数学符号怎样输入,改怎样处理??
- 无法插入空行.行必须至少有一个列值集.
- 如何让DBGrid中显示的日期格式是年为4位(菜鸟问题)
- 在windows NT的域服务器上为什么不能装informix数据库?
- 高分奉送,一个想去上海发展的同行的请求!!!!!!!!!!!!!!! 100分!!!!!
type
PSortInfo = ^TSortInfo;
TSortInfo = record
Col : Integer;
Style : TSortStyle;
Asc : Boolean;
end;function ListViewCompare(I1, I2: TListItem; Data: Integer): Integer; stdcall;
var
V1, V2: string; function Sign(Val: Extended): Integer;
begin
if Val < 0 then
Result := -1
else if Val > 0 then
Result := 1
else
Result := 0;
end; function ExtractNum(const S: string): string;
var
i, j: Integer;
begin
j := 0;
for i := 1 to Length(S) do
if S[i] in ['0'..'9'] then
Inc(j)
else
Break;
if j = 0 then
Result := '0'
else
Result := Copy(S,1,j);
end;
begin
with PSortInfo(Data)^ do
begin if Col = 0 then
begin
V1 := I1.Caption;
V2 := I2.Caption;
end
else
begin
V1 := I1.SubItems[Col-1];
V2 := I2.SubItems[Col-1];
end; case Style of
ssAlpha : Result := AnsiCompareText(V1,V2);
ssNumeric : Result := Sign(StrToFloat(ExtractNum(V1))-StrToFloat(ExtractNum(V2)));
ssDateTime : Result := Sign(StrToDateTime(V1) - StrToDateTime(V2));
else
Result := 0;
end; if not Asc then
Result := -Result;
end;
end;procedure SortListView(ListView:TListView; ColumnIndex:Integer;
Style: TSortStyle; Ascending: Boolean=True);
{排序ListView,ColumnIndex:排序列索引号,
Style 排序方式:按字符,按数值,按日期(日期格式为
SysUtils.ShortDataTimeFmt,缺省为YY-MM-DD);
Ascending:=True按升序,否则按降序}
var
FSortInfo:TSortInfo;
begin
FSortInfo.Col := ColumnIndex;
FSortInfo.Style := Style;
FSortInfo.Asc := Ascending;
ListView.CustomSort(@ListViewCompare,LongInt(@FSortInfo));
end;