Sorting TListView Columns

后端 未结 1 496
不知归路
不知归路 2021-01-22 09:59

I have a TListview with 4 columns (which are all strings of course) however, I store data in them as such:

  • Caption: any string

1条回答
  •  再見小時候
    2021-01-22 10:51

    If you have two strings that contain integers and you wish to compare as integers then convert them from text to integer, and compare numerically.

    function CompareTextAsInteger(const s1, s2: string): Integer;
    begin
      Result := CompareValue(StrToInt(s1), StrToInt(s2));
    end;
    

    And similarly for dates. Convert them from text to numeric values, for example TDateTime values. And then compare numerically.

    function CompareTextAsDateTime(const s1, s2: string): Integer;
    begin
      Result := CompareDateTime(StrToDateTime(s1), StrToDateTime(s2));
    end;
    

    Exactly how you implement this latter function depends on how you want to convert from text to numeric representation of date/time.

    0 讨论(0)
提交回复
热议问题