[fpc-devel] Variants and strings

Joost van der Sluis joost at cnoc.nl
Mon Dec 20 17:55:30 CET 2004


On Mon, 2004-12-20 at 17:13 +0100, Michael Van Canneyt wrote:
> 
> On Mon, 20 Dec 2004, Joost van der Sluis wrote:
> 
> > > > I've found a problem in the string-implementation of the variants, but I
> > > > thought I would better discus it first, before I start doing all sort of
> > > > work for nothing.

> > > > So I want to suggest to change the string-support in variants form
> > > > PWideChar into Widestrings. This is also more Delphi-compatible.
> > > > According to the Delphi help strings in variants are stored in
> > > > Widestrings...
> > >
> > > This is not quite true. (or it may depend on the Delphi version)
> > >
> > > "if a variant containing an AnsiString is assigned to an OleVariant,
> > > the AnsiString becomes a WideString."
> >
> > Yep, but in FPC (Linux, haven't looked into win32 stuff), variants can't
> > contain any ansistrings. There are only two 'string-types' available in
> > FPC's variants: PWideChar (which they call OleVariant, partially
> > implemented as widestrings as I stated above) and VarString, which
> > aren't implemented or used any further.
> >
> > On Delphi there are shortstrings, widestrings, ansistrings, pwidechars,
> > widechars and pchars. (see the help on TVarRec) This is all very
> > different from the implementation in FPC.
> 
> TVarRec has nothing to do with Variants. TVarRec is for the Array of
> Const implementation. TVarData is for a variant.

You're right, sorry. 

> > > So this needs some thinking, and some input from the compiler guys.
> >
> > Probably, yes. (compiler guys, anyone?)
> > Basically I think that we should look how win32 handles this, and
> > implement it that way into linux/other OS's.
> 
> Not yet:
> 
> I had a closer look at the Delphi implementation (D5).
> They use varString (an internal type) which is not known
> by Windows. It is handled specially by the Delphi code.
> (That is probably why it is not present in FPC...)

That's the VarString, as implemented in FPC, which isn't used.

> Now, whenever a variant is passed to windows, it is converted
> to an OleVariant, which does the conversion from varString
> to varOleString.
> 
> What I think we can do is add support for varstring, and use that to
> store the ansistring. The PWideChar conversion stuff can then be added
> later, when we have COM support.
> 
> Do you think you can do this, or do you want me to have a go at it ?

I'll give it a try. If I need help, or if I don't succeed I will contact
you. 

-- 
Met vriendelijke groeten,

  Joost van der Sluis
  CNOC Informatiesystemen en Netwerken
  http://www.cnoc.nl





More information about the fpc-devel mailing list