[fpc-pascal] PWideChar vs. ^

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Mar 13 18:14:09 CET 2009

On 13 Mar 2009, at 17:46, Marc Santhoff wrote:

> maybe this is a dumb question, but:
> If I have a variable declared as
>  var
>    s: PWideString;
> why is an exception (AV) thrown when using
>    something := s^;
> but not when using
>    something := PWideChar(s);
> ?
> Maybe this is special behaviour of the routine getting the variable,  
> it
> is
>  TTreeView.AddChild(ParentNode: TTreeNode; const s: string): TTreeNode

1) you're not saying what the type of "something" is
2) a pwidechar and a pwidestring are completely different things (a  
pwidestring points to a widestring, which i, turn is sort of like a  
reference-counted pwidechar; so typecasting a pwidestring to a  
pwidechar does not make sense)
3) you're not showing how the pwidestring was allocated and initialised
4) the "s" parameter in the procedure definition at the end is a  
string, while in the other code it's a pwidestring. It is also not  
clear to me what this routine has to do with any of the other code  
snippets that you posted

Please always include a compilable sample program when asking  
questions about code behaviour. Without it, all that can be done is  
hand waving. It may be more work for you, but it saves a lot of time  
asking questions after which that work has to be done anyway.


More information about the fpc-pascal mailing list