Re: [Lazarus] Example of TObjectList sorting

2016-05-23 Thread Richard Mace
On 22 May 2016 at 11:22, Ondrej Pokorny  wrote:

> You are using "procedure of object" where you need "procedure".
>

​Thanks Ondrej, that sorted it :)
​
​Thanks for everyone's help​

Richard
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-22 Thread Ondrej Pokorny

You are using "procedure of object" where you need "procedure".

(One solution is to add static keyword to your procedure declaration, if 
the FPC version you use supports the typecast - iirc, fpc 3.0.0 can't do 
that in objfpc mode.)



Ondrej


On 22.05.2016 12:17, Richard Mace wrote:

Thanks Denis,

I am now getting:

inboundroutedestlist.pas(49,35) Error: Incompatible type for arg no. 
1: Got "of object;Register>", expected "function(Pointer;Pointer):LongInt;Register>"


Any ideas?

Richard

On 22 May 2016 at 07:30, Denis Kozlov > wrote:



On 21 May 2016 at 13:49, Richard Mace mailto:[email protected]>> wrote:

​Would I call the List.sort externally, or would the List call
sort when an Add has happened, as I don't seem to have a
".sort" method on my TObjectList?


You need to call List.Sort yourself, it is not sorted
automatically when you add more elements.

TObjectList does have a Sort method, since it descends from TList
class.

Denis



--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-22 Thread Richard Mace
Thanks Denis,

I am now getting:

inboundroutedestlist.pas(49,35) Error: Incompatible type for arg no. 1: Got
"", expected ""

Any ideas?

Richard

On 22 May 2016 at 07:30, Denis Kozlov  wrote:

>
> On 21 May 2016 at 13:49, Richard Mace  wrote:
>
>> ​Would I call the List.sort externally, or would the List call sort when
>> an Add has happened, as I don't seem to have a ".sort" method on my
>> TObjectList?
>>
>
> You need to call List.Sort yourself, it is not sorted automatically when
> you add more elements.
>
> TObjectList does have a Sort method, since it descends from TList class.
>
> Denis
>
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-21 Thread Denis Kozlov
On 21 May 2016 at 13:49, Richard Mace  wrote:

> ​Would I call the List.sort externally, or would the List call sort when
> an Add has happened, as I don't seem to have a ".sort" method on my
> TObjectList?
>

You need to call List.Sort yourself, it is not sorted automatically when
you add more elements.

TObjectList does have a Sort method, since it descends from TList class.

Denis
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-21 Thread Richard Mace
Hi Denis,

Thanks for your reply.

On 9 May 2016 at 13:24, Denis Kozlov  wrote:

> On 9 May 2016 at 12:48, Richard Mace  wrote:
>
>> I have a TObjectList that contains many objects that have a property
>> called "Position" which is an integer.
>>
>> Could somebody show me an example of the code that I will need to create
>> that will sort all of my Objects within the TObjectList so that they are in
>> position order e.g. 1,2,3,4,5 and so on?
>>
>
> Call TList.Sort method and supply a comparison function.
>
>
> For example:
>
> List.Sort(@CompareByPositionPtr);
>

​Would I call the List.sort externally, or would the List call sort when an
Add has happened, as I don't seem to have a ".sort" method on my
TObjectList?

Thanks​

​Richard​
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-09 Thread Graeme Geldenhuys
On 2016-05-09 14:12, Denis Kozlov wrote:
> Also, forums are more easily
> searched, indexed by search engines and easier to view for novice users.


Lets agree to disagree.  ;-)

ps:
  The mailing lists are also searched and indexed by search engines -
  thanks to services like Nabble and many others. But then again, my
  email client does just fine searching on its own (and can do it
  offline).

  http://free-pascal-lazarus.989080.n3.nabble.com/
  http://free-pascal-general.1045716.n5.nabble.com/


Regards,
  Graeme



--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-09 Thread Denis Kozlov
On 9 May 2016 at 13:44, Graeme Geldenhuys 
wrote:

> On 2016-05-09 13:24, Denis Kozlov wrote:
> > This kind of question is better suited on the forum I think
>
> Why? This mailing list is just as much a support area as the web forum.
> Not everybody likes web based forums (I don't).
>

Forum is especially good for tutorials, generic and commonly asked
questions - like a repository of knowledge, Also, forums are more easily
searched, indexed by search engines and easier to view for novice users.
Hence, I think this question/answer would reach more end users while being
on the forum, instead of on a mailing list.

Denis
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-09 Thread Graeme Geldenhuys
On 2016-05-09 13:24, Denis Kozlov wrote:
> This kind of question is better suited on the forum I think

Why? This mailing list is just as much a support area as the web forum.
Not everybody likes web based forums (I don't).

Granted the question related more to the RTL that Lazarus or LCL, so if
anything, it could have been posted in the fpc-users mailing list.  But
you were kind enough to answer anyway. ;-)


Regards,
  Graeme


--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-09 Thread Denis Kozlov
On 9 May 2016 at 12:48, Richard Mace  wrote:

> I have a TObjectList that contains many objects that have a property
> called "Position" which is an integer.
>
> Could somebody show me an example of the code that I will need to create
> that will sort all of my Objects within the TObjectList so that they are in
> position order e.g. 1,2,3,4,5 and so on?
>

Call TList.Sort method and supply a comparison function.


For example:

List.Sort(@CompareByPositionPtr);

function CompareByPosition(A, B: TMyObject): Integer; inline;
begin
  if A.Position < B.Position then
Result := -1
  else if A.Position > B.Position then
Result := 1
  else
Result := 0;
end;

function CompareByPositionPtr(A, B: Pointer): Integer;
begin
  Result := CompareByPosition(TMyObject(A), TMyObject(B));
end;


This kind of question is better suited on the forum I think

Denis
--
___
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus