Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-02

Make TStringList.ExchangeItems virtual?

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Is it at all feasible to make TStringList.ExchangeItems a virtual method?

Reason:
In Lazarus we have a component (TValueListEditor) that has a TStringList descendant as one of it's properties.
This particular list needs te bee in sync with another list of objects.

For Insert, Delete, Exchange and Clear that is easily done. However sorting is a problem, because CustomSort calls QuickSort which internally uses ExchangeItem() and not Exchange (which is virtual).

For now I just duplicated the QuickSort and replaced ExchangeItem with (the overridden) Exchange.
This however has the distinct disadvantage of having duplicate code.

And yes, I thought about storing the other objects inside the stringlist, so they are automatically sorted as well, but then I would get into trouble if some user decide to store objects inside this stringlist (because he would not expect that this caused the component to not function properly anymore).

Since I'm ignorant of possible side effects, I thought I'ld better first ask here, before filing a feauture request on the bugtracker.

Bart

Sven Barth
to Bart
Bart wrote 16 lines
Hi, Is it at all feasible to make TStringList.ExchangeItems a virtual method? Reason: In Lazarus we have a component (TValueListEditor) that has a TStringList descendant as one of it's properties. This particular list needs te bee in sync with another list of objects. For Insert, Delete, Exchange and Clear that is easily done. However sorting is a problem, because CustomSort calls QuickSort which internally uses ExchangeItem() and not Exchange (which is virtual). For now I just duplicated the QuickSort and replaced ExchangeItem with (the overridden) Exchange. This however has the distinct disadvantage of having duplicate code.

And it calls OnChanging and OnChange and notifies the observers each time an item is swapped... (at least if the Sort is not done inside a BeginUpdate/EndUpdate pair...)

So in that case I'd prefer the "virtualisation" of ExchangeItems as well...

Regards,
Sven

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 21 lines
On 13.02.2013 15:43, Bart wrote: > Hi, > > Is it at all feasible to make TStringList.ExchangeItems a virtual method? > > Reason: > In Lazarus we have a component (TValueListEditor) that has a > TStringList descendant as one of it's properties. > This particular list needs te bee in sync with another list of objects. > > For Insert, Delete, Exchange and Clear that is easily done. > However sorting is a problem, because CustomSort calls QuickSort which > internally uses ExchangeItem() and not Exchange (which is virtual). > > For now I just duplicated the QuickSort and replaced ExchangeItem with > (the overridden) Exchange. > This however has the distinct disadvantage of having duplicate code. And it calls OnChanging and OnChange and notifies the observers each time an item is swapped... (at least if the Sort is not done inside a BeginUpdate/EndUpdate pair...)

Currently it is not, in fact this should be done automatically.

So in that case I'd prefer the "virtualisation" of ExchangeItems as well...

We can do that, but it wouldn't do much good, since it is private. So I guess we'd have to make it protected too.

The disadvantage is that making it virtual will make it slower, since an additional VMT lookup must be done. The reason that it is a separate routine is exactly to make it faster, otherwise quicksort could just have used Exchange()..

Michael.

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote 29 lines
On Wed, 13 Feb 2013, Sven Barth wrote: > On 13.02.2013 15:43, Bart wrote: >> Hi, >> >> Is it at all feasible to make TStringList.ExchangeItems a virtual >> method? >> >> Reason: >> In Lazarus we have a component (TValueListEditor) that has a >> TStringList descendant as one of it's properties. >> This particular list needs te bee in sync with another list of objects. >> >> For Insert, Delete, Exchange and Clear that is easily done. >> However sorting is a problem, because CustomSort calls QuickSort which >> internally uses ExchangeItem() and not Exchange (which is virtual). >> >> For now I just duplicated the QuickSort and replaced ExchangeItem with >> (the overridden) Exchange. >> This however has the distinct disadvantage of having duplicate code. > > And it calls OnChanging and OnChange and notifies the observers each > time an item is swapped... (at least if the Sort is not done inside a > BeginUpdate/EndUpdate pair...) Currently it is not, in fact this should be done automatically.

Than this could be adjusted at least...

Show quoted text 6 lines
> So in that case I'd prefer the "virtualisation" of ExchangeItems as > well... We can do that, but it wouldn't do much good, since it is private. So I guess we'd have to make it protected too.

I have silently assumed this :)

The disadvantage is that making it virtual will make it slower, since an additional VMT lookup must be done. The reason that it is a separate routine is exactly to make it faster, otherwise quicksort could just have used Exchange()..

Exchange additionally contains checks and two further method calls that do complex stuff if BeginUpdate was not called, so one can argue what is faster here :)

We could maybe adjust the string list in so far that at the beginning of QuickSort we determine whether ExchangeItem was overridden, if it was we call the now virtual, protected ExchangeItem and if it was not overriden we call a private non virtual version (which could be called by the default implementation of ExchangeItem as well).

Just a stupid idea to make the code more complex :P

Regards,
Sven

Bart
to Sven Barth
Sven Barth wrote 5 lines
We could maybe adjust the string list in so far that at the beginning of QuickSort we determine whether ExchangeItem was overridden, if it was we call the now virtual, protected ExchangeItem and if it was not overriden we call a private non virtual version (which could be called by the default implementation of ExchangeItem as well).

Should I open a ticket in bugtracker for this?

Bart

Michael Van Canneyt
to Bart
Bart wrote 9 lines
On 2/13/13, Sven Barth wrote: > We could maybe adjust the string list in so far that at the beginning of > QuickSort we determine whether ExchangeItem was overridden, if it was we > call the now virtual, protected ExchangeItem and if it was not overriden > we call a private non virtual version (which could be called by the > default implementation of ExchangeItem as well). Should I open a ticket in bugtracker for this?

Yes, please.

Michael.

Dennis Poon
to Michael Van Canneyt

I know I can download the archived zip files but can I search it? Is there any web site where I can search the archive?

Searching on google never return anything from this elist but I was told most supports happen on this list.

Many thanks.

Dennis

Dennis Poon
to Michael Van Canneyt: Yes, please. Michael.

As told by the objectivepascal web site,
I download and installed the template
http://dl.dropbox.com/u/28343282/ObjP/Xcode_Templates.html

however, when I compiled an IOS project, it stuck at the unit not found iPhoneAll.pas
I tried to give it a full path by changing it to:

uses
iPhoneAll in
'/Developer/FreePascalCompiler/fpc-2.6.0/packages/cocoaint/utils/uikit-skel/src/iPhoneAll.pas',

   Test1AppDelegateU;

but then, I got
iPhoneAll.pas(19,3) Fatal: Can't find unit AnonClassDefinitionsUikit used by iPhoneAll

It seems like a loop of problems so I am stuck.

I tried to run the make-ios-headers.sh script but it said: $ sh make-ios-headers.sh
iOS SDK base path
"/Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS4.2.sdk" not found, specify it as the first parameter to this script. Note that this parser version has only been verified to work with the iOS SDK 4.2

I worried even if I fixed the parameter, it will still have n more problems. Anyone succeeded in using xcode 4.6 for free pascal?

Thanks in advance for any tips.

Dennis