[fpc-pascal] Help making code unicode capable
Marco van de Voort
marcov at stack.nl
Sat Nov 10 15:20:05 CET 2007
> On 10 Nov 2007, at 15:08, Felipe Monteiro de Carvalho wrote:
>
> > Having a win9x version is trivial, but having a version where we put a
> > PWideChar into lpStrFilter looks hard...
> >
> > lpStrFilter := StrAlloc(Length(Filter)+1);
> > StrPCopy(lpStrFilter, Utf8ToAnsi(Filter));
> >
> > I tryed this as unicode version:
> >
> > lpStrFilter := PChar(PWideChar(Utf8Decode(Filter)));
> >
> > But it crashes the dialog when it is closed... I don't know what
> > exactly is happening here, or why the original code manually alocated
> > memory and then copyed the string, instead of just copying,
>
> Maybe because Filter may already have disappeared/freed by the time
> the dialog is closed? (and for some reason it may still need that text
> at that time)
utf8decode returns string I assume?. I think it is that tempstring that is lost.
Moreover, the first piece of code assumes that
length(filter)>=length(utf8toansi(filter))
I think that is ok in general, but I would assign the result of utf8toansi
to a local string first, because even if a shortcut abusing temps works,
that will be more comprehensive.
More information about the fpc-pascal
mailing list