![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
наследник TObjectList
Iriss © (2009-02-10 10:26:00)Есть тип TContainerPump - наследник от TObjectList
type TContainerPump = class(TObjectList)
public constructor Create;
public function Add (APump: TPump): Integer;
public function Remove (APump: TPump): Integer;
public function IndexOf(APump: TPump): Integer;
public function First : TPump;
public function Last : TPump;
public procedure Sort(Compare: TListSortCompare);
private function GetItem(Index: Integer): TPump;
private procedure SetItem(Index: Integer; APump: TPump);
public property Items[Index: Integer]: TPump read GetItem write SetItem; default;
end;
хочу отсортировать список
var ContainerPumps: TContainerPump;
ContainerPumps.Sort( compareByMaxPower );
где
function TPumpsOptimal.compareByMaxPower(Pump1, Pump2: TPump) : Integer;
begin
if ( Pump1.MaxPower > Pump2.MaxPower )
then Result := 1
else begin
if Pump1.MaxPower = Pump2.MaxPower
then Result := 0
else Result := -1;
end;
end;
выдает ошибку
несоответствие типов: regular procedure and method pointer
понимаю, что
TListSortCompare = function (Item1, Item2: Pointer): Integer;
у меня Item типа TPump, но не понимаю как исправить ошибку.
Подскажите, please
Anatoly Podgoretsky (2009-02-10 11:08:00) [1]> Iriss (10.02.2009 10:38:02) [2]
Врешь!
У тебя
function TPumpsOptimal.compareByMaxPower(Pump1, Pump2: TPump) : Integer;
а в примере
function compareByName(Item1 : Pointer; Item2 : Pointer) : Integer;
Iriss (2009-02-10 10:55:00) [2]разобрался, спасибо большое
Плохиш (2009-02-10 10:44:00) [3]
> Iriss (10.02.09 10:38) [2]
> > адрес регулярной процедуры
> что такое регулярная процедура?
Это обычная процедура, описанная в документации по языку паскаль, не являющаяся методом какого-либо класса. Пример, readln.
PS. А тебе, вообще-то, функцию надо.
Сергей М. (2009-02-10 10:42:00) [4]
> Iriss (10.02.09 10:38) [2]
> делал все вроде бы так же как здесь
Ну где же так же ?
Сравни оригинал
function compareByName(Item1 : Pointer; Item2 : Pointer) : Integer;
и своё
function TPumpsOptimal.compareByMaxPower(Pump1, Pump2: TPump) : Integer;
В чем главноеотличие ?
Iriss (2009-02-10 10:38:00) [5]делал все вроде бы так же как здесь
http://www.delphisources.ru/pages/faq/faq_delphi_basics/TList.php.html
Просветите темного:
> адрес регулярной процедуры
что такое регулярная процедура?
Сергей М. (2009-02-10 10:31:00) [6]
> у меня Item типа TPump, но не понимаю как исправить ошибку
Это не имеет ни малейшего отношения к наблюдаемой тобой ошибке.
> несоответствие типов: regular procedure and method pointer
Метод Sort требует параметром адрес регулярной процедуры, а ты пытаешься скормить ему адрес метода класса.