[fpc-pascal] random question

2010-06-04 Thread 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] random question

2010-06-04 Thread Michael Van Canneyt



On Fri, 4 Jun 2010, spir wrote:


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.




-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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] random question

2010-06-04 Thread Jonas Maebe


On 04 Jun 2010, at 15:22, Michael Van Canneyt mich...@freepascal.org  
wrote:



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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] random question

2010-06-04 Thread Vladimir Zhirov
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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] random question

2010-06-04 Thread Vladimir Zhirov
 by declaring the property and pressing Ctrl+C

Sorry, I meant Ctrl+Shift+C

-- 
Regards,
Vladimir Zhirov
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] random question

2010-06-04 Thread Graeme Geldenhuys
On 4 June 2010 15:19, 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/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal