Sortowanie ListView problem

0

Mam problem przy sortowaniu ListView wywala mi błąd [DCC Error] zam_list.pas(177): E2003 Undeclared identifier: 'CompareValue' - mam delphi 2007 for win32 prof.

procedure Tzam_lista.ListViewFirmaColumnClick(Sender: TObject;
Column: TListColumn);
begin
inSortColumnRep := Column.Index;
ListViewFirma.AlphaSort;
InvartSort := not InvartSort;
end;

procedure Tzam_lista.ListViewFirmaCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
case inSortColumnRep of
0 {File} : {zerowe trzeba porównywać przez caption}
compare := CompareStr(Item1.Caption, Item2.Caption);
1 {Size} :
compare := CompareValue(
StrToInt(Item1.SubItems.Strings[inSortColumnRep - 1]),
StrToInt(Item2.SubItems.Strings[inSortColumnRep - 1]));
else
compare := CompareStr(
Item1.SubItems.Strings[inSortColumnRep - 1],
Item2.SubItems.Strings[inSortColumnRep - 1]);
end;

if InvartSort then
compare := compare * -1;
end;

0

To znaczy że kompilator nie znalazł takiej funkcji czyli nie masz dołączonego odpowiedniego unita.
Dopisz do listy uses moduł Math;

0
BumaDruma napisał(a)

Dopisz do listy uses moduł Math;

Edit: Pytanie za głupie na publikacje :)

0
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
if (Item1=nil) and (Item2=nil) then
  Compare:=0
 else
 if (Item1=nil) and (Item2<>nil) then
  Compare:=-1
 else
 if (Item1<>nil) and (Item2=nil) then
  Compare:=1
 else
 if Data=0 then
  Compare:=ComPareStr(Item1.Caption,Item2.Caption)
 else
 // sanity check
 if (Data<=Item1.SubItems.Count) and (Data<=Item2.SubItems.Count) then
  Compare:=ComPareStr(Item1.SubItems[Data-1],Item2.SubItems[Data-1]);
 // sort by name as second criteria
 if (Compare=0) and (Data<>0) then
  ListView1Compare(sender,Item1,Item2,0,Compare);
end;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
begin
ListView1.CustomSort(nil,Column.index);
end;
0
RedbaK napisał(a)
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
if (Item1=nil) and (Item2=nil) then
  Compare:=0
 else
 if (Item1=nil) and (Item2<>nil) then
  Compare:=-1
 else
 if (Item1<>nil) and (Item2=nil) then
  Compare:=1
 else
 if Data=0 then
  Compare:=ComPareStr(Item1.Caption,Item2.Caption)
 else
 // sanity check
 if (Data<=Item1.SubItems.Count) and (Data<=Item2.SubItems.Count) then
  Compare:=ComPareStr(Item1.SubItems[Data-1],Item2.SubItems[Data-1]);
 // sort by name as second criteria
 if (Compare=0) and (Data<>0) then
  ListView1Compare(sender,Item1,Item2,0,Compare);
end;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
begin
ListView1.CustomSort(nil,Column.index);
end;

I wyskakuje [DCC Error] unit2.pas(219): E2038 Illegal character in input file: '"' (#$22)

A co do wcześniejszego dzięki za pomoc działa z tym że mam kolumny Id | symbol | nazwa |
Po Id i nazwa sortuje natomiast po klinięciu na symbol wywyala błąd {3 pozycja listy} is not a valid integer value;

0

A co do wcześniejszego dzięki za pomoc działa z tym że mam kolumny Id | symbol | nazwa |
Po Id i nazwa sortuje natomiast po klinięciu na symbol wywyala błąd {3 pozycja listy} is not a valid integer value;

No bo symbol to jest raczej innego typu danych.

A tak w ogóle sortowanie danych w Listview ustawiasz w samym oknie Properties bez żadnego tam kodu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1