[lazarus] Patches to Shanes files

Shane Miller SMiller1 at stvgb.org
Wed Jul 7 17:16:30 EDT 1999


I'm using sysutils in gtkint.pp not strings.

Shane


>>> <michael at tfdec1.fys.kuleuven.ac.be> 07/07 3:54 PM >>>


On Wed, 7 Jul 1999, Payne Thomas E CNIN wrote:

> FYI
> 
> This works with 0.99.12a of win32
> ----------------------
> program test;
> {$mode objpas}
> uses strings;
> var
>   newpchar : Pchar;
>   stringvar : String;
> begin
>   stringvar := '>hello<';
>   newpchar := StrAlloc(Length(StringVar)+1);
>   StrPCopy(newPChar,StringVar);
>   writeln(string(newpchar));
> end.

This is Correct. 
In objpas mode a pchar can be typecast to a shortstring.

> ----------------------
> 
> This does not
> ---------------------
> program test;
> {$mode delphi}
> uses strings;
> var
>   newpchar : Pchar;
>   stringvar : String;
> begin
>   stringvar := '>hello<';
>   newpchar := StrAlloc(Length(StringVar)+1);
>   StrPCopy(newPChar,StringVar);
>   writeln(string(newpchar));
> end.

In delphi mode, you can't typecast a pchar to a SHORTstring.
You can, however, do it if you use the -Sh switch or {$H+} 
so the string is an ansistring. I that case the program 
works correctly.

For both cases: 

1) The typecast isn't needed. You can directly write
   the value of the pchar.
2) NEVER use the 'strings' unit if you use ansistrings;
   the strings unit returns shortstrings only. If you do this,
   you get an additional conversion to ansistring.
   Instead, use the 'sysutils' unit; it has the same routines
   as 'strings', only with ansistrings.

Michael.

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus






More information about the Lazarus mailing list