Sign in Join

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

Mailing lists / fpc-pascal / 2010-06

random question

6 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

spir

Hello Pascaleers,

-1- class wrappers
Are there in stock implementations of class wrappers for primitive types: such as TInteger, TString, etc? (that would for instance just hold a .value attr and delegate operations to builtin funcs or procs) This would save me some work :-)

-2- [] operator
How to implement a class that manages this operator (did not find it in the operator overloading section). Pointer welcome (including to the implementation of eg TFPList).

-3- List specialization
What is actually needed to specialise TFPList or TObjectList, in order for an instance of the new list class to hold as elements instances of a subclass of TObject. (The main purpose for this specialisation is to avoid systematically casting back elements to TMyObject). I guess I only need to redefine the .List or .Items property, but to do what, actually (maybe the main issue jumps back to question -2-)?

Denis
________________________________

vit esse estrany ☣

spir.wikidot.com

Reply by email

Michael Van Canneyt
to spir
spir wrote 5 lines
Hello Pascaleers, -1- class wrappers Are there in stock implementations of class wrappers for primitive types: such as TInteger, TString, etc? (that would for instance just hold a .value attr and delegate operations to builtin funcs or procs) This would save me some work :-)

No. They are planned. They partially exist for the objectivec import layer. (although they may be semantically different there)

-2- [] operator How to implement a class that manages this operator (did not find it in the operator overloading section). Pointer welcome (including to the implementation of eg TFPList).

[] is not an operator. It is a set notation.

Or it is used as a notation for selecting elements from an array. But that also is not an operator.

Show quoted text 8 lines
-3- List specialization What is actually needed to specialise TFPList or TObjectList, in order for an instance of the new list class to hold as elements instances of a subclass of TObject. (The main purpose for this specialisation is to avoid systematically casting back elements to TMyObject). I guess I only need to redefine the .List or .Items property, but to do what, actually (maybe the main issue jumps back to question -2-)?

What you want - no typecasts - needs to be accomplished using generics, see the fgl unit.

If typecasts are OK: just look at the contnrs unit, there you have several descendents of the TList class.

Michael.

Reply by email

Jonas Maebe
to Michael Van Canneyt
Michael Van Canneyt wrote 13 lines
On Fri, 4 Jun 2010, spir wrote: > > -1- class wrappers > Are there in stock implementations of class wrappers for primitive > types: such as TInteger, TString, etc? (that would for instance > just hold a .value attr and delegate operations to builtin funcs or > procs) This would save me some work :-) No. They are planned. They partially exist for the objectivec import layer. (although they may be semantically different there) > >

They don't exist in Objective-C (and hence not in Objective-Pascal either)

Maybe you were thinking about class helpers, but that's something different.

Jonas

Reply by email

Vladimir Zhirov
to spir: -1- class wrappers Are there in stock implementations of class wrappers for primitive…
spir wrote
-2- [] operator How to implement a class that manages this operator (did not find it in the operator overloading section). Pointer welcome (including to the implementation of eg TFPList).

It seems default properties is what you are looking for.

> type > TMyClass = class > ... > property Items[AnIndex: Integer]: TMyItem read GetItem write SetItem; default;

Note the "default" keyword, it allows you to access Items like this:

> MyClassInstance[1]

instead of

> MyClassInstance.Items[1]

You can also use string instead of Integer index, then accessing such property would look like dealing with associative arrays:

> MyClassInstance['first']

or

> MyClassInstance.Items['first']

GetItem and SetItem methods must take the appropriate parameters, and return the appropriate result. You can let Lazarus generate them for you by declaring the property and pressing Ctrl+C while cursor is on the same line with your property declaration.

Regards, Vladimir Zhirov

Reply by email

Graeme Geldenhuys
to spir: -1- class wrappers Are there in stock implementations of class wrappers for primitive…
spir wrote
-1- class wrappers Are there in stock implementations of class wrappers for primitive types: such as TInteger, TString, etc? (that would for instance just hold a .value attr and delegate operations to builtin funcs or procs) This would save me some work :-)

The tiOPF project has those implemented in the tiObject.pas unit. I implemented my own about a year ago, but never really used it in any real-world projects. Lee Jenkins also wrote something similar (VTF - Value Type Framework).

tiOPF is on SourceForge.

Lee's svn repository is at:
http://leebo.dreamhosters.com/VTF

My code is somewhere on my hard drive.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email