[fpc-pascal] The new Delphi compatible unicode string

Marco van de Voort marcov at stack.nl
Tue Jan 4 16:57:43 CET 2011


In our previous episode, Juha Manninen said:
> > 
> > I am in the process of converting a D7 application to a D2010 application.
> > There are lots of string encoding problems, and none of them is solved
> > "automatically".
> 
> What kind of problems did you have?

First, D2009 only solves labelling stringtypes with encoding. This means
that all inputs must be correctly labeled, or the system falls apart. And
all code must be sufficiently highlevel enough (you can still mutilate
utf8-strings with simple delete operations)

Any lowlevel operations must also be checked.
 
> I used Delphi 2009 for a while at my former workplace. At least it worked with 
> my existing Delphi programs amazingly well. The compiler sometimes warned 
> about automatic conversion between string types but still it worked.

The conversion was non trivial, and the improvements must not be exaggerated.
It is a small addition to better unicode support, not the big one. THat must
come from cleaning up the code, making the codepaths safe and labelling
sources of strings outside the compilers control (OS/GUI/e.g. streamed
files) properly.
 
> The string uses UTF-16 encoding and converts automatically from other
> string types.

_IF_ those are properly labelled. But widestring:=ansisstring; does the same
in older versions too. It was just that there was only one "label" (the
current ANSI encoding) Now there is a chance at several.

> > Furthermore, if you need to support both the old and new string type
> > (i.e. keep it compilable with older Delphi/FPC versions) you'll always
> > need IFDEFS in your code.

> No, my whole idea is to modernize the code and NOT support old versions.

And what if it doesn't work? That is the whole problem. You can't as with
other versions first migrate the code to roughly work on the new delphi (fix
components etc), validate stability, and only then start using new
functionality. 

D2009 is a watershed, and a painful one (even if the feature itself can be
considered good, which I do)

> I am often questioning myself if it makes sense to use this historical 
> language.

Me too. Trouble is that I don't see anything else in which I'm half as
productive. C++ makes sense, but the only halfwhat productive one is from
the same small company as Delphi.

> As you know most programmers consider it a dead or at least a dying language.

True. But I don't get paid by other programmers if I follow their choices. I
get paid for delivering apps to clients.

> However it is advancing to a right direction so I am still here.
> The problem seems to be more the old code base and the programmers' attitude 
> against using the modern features.

>From what I see, the Delphi crowd often has very large investments. Simply
becuase it is a tool with codebases dating back to 1995.
 
> If I told to a Java programmer that Object Pascal features match Java 
> features, how would I prove it? By showing him the HTML component code?

I would not argue features, but delivery time.




More information about the fpc-pascal mailing list