Search the web
Sign In
New User? Sign Up
GPCP · Gardens Point Component Pascal
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Is this a GPCP bug?   Message List  
Reply | Forward Message #425 of 437 |
Re: Is this a GPCP bug?

--- 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






Thu Jul 2, 2009 12:29 am

cfbsoftware1
Offline Offline
Send Email Send Email

Forward
Message #425 of 437 |
Expand Messages Author Sort by Date

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...
Marc Martin
marcmartin2
Offline Send Email
Jul 1, 2009
6:06 pm

... 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...
cfbsoftware1
Offline Send Email
Jul 2, 2009
12:29 am

... Yes, in the original code, this was part of an initialization sequence. The debugger claims that the crash happens with the assignment, not with an access....
Marc Martin
marcmartin2
Offline Send Email
Jul 2, 2009
1:48 am

... Sorry, my mistake, I misread your original message. Your question makes a lot more sense to me now! You are right - it shouldn't crash when you assign: str...
cfbsoftware1
Offline Send Email
Jul 2, 2009
2:42 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help