--- In GPCP@yahoogroups.com, "Marc Martin" <marc@...> wrote:
>
> Hi all,
>
> I noticed that if I assign a System.String to NIL,
> the code will crash with an error in RTS.dll. I'm
> wondering if this is a GPCP bug, of I am misunderstanding
> what I can do with a System.String?
>
> Example code:
>
> MODULE Hello;
>
> IMPORT System := "[mscorlib]System", CPmain;
>
> VAR
> str: System.String;
> BEGIN
> str := NIL;
> System.Console.WriteLine( str );
> END Hello.
>
> Debugger error message at "str := NIL":
>
> An unhandled exception of type 'System.NullReferenceException'
> occurred in RTS.dll
>
There is no problem assigning NIL to str, but there certainly is a problem if
you then try to access that variable.
Efectively you are telling the system that the variable is no longer in use.
Hence, the garbage collector can free up any memory, that may have been
previously allocated to it, to be used by something else. The associated
variable then becomes 'undefined' and cannot be subsequently referenced in an
expression until you reinitialise it e.g.
str := "abc";
If you wanted to create an empty string then you should have written:
str := "";
otherwise what were you attempting to do?
Regards,
Chris Burrows
CFB Software
CPIde v3.1: An IDE for Component Pascal
http://www.cfbsoftware.com/cpide