Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Undesired Constant String [NEW problem]

  1. #1

    Undesired Constant String [NEW problem]

    Well, this is a new one. Basically, it won't let me have a string longer than 255 chars long, because it is, for some reason, constant.
    [pascal]
    type
    TRoom = Class
    public
    n,s,e,w: string;
    objects: array[0..10] of integer;
    objectloc: array[0..10] of string;
    title: string;
    rdesc: string;
    end;
    [/pascal]
    Why would it be considered a constant? And is there any way to change that? Any other code you think would be necessary to see?

    (I seem to manage fairly well in learning new languages until these little nuances come up )

  2. #2

    Re: Undesired Constant String

    Considered a constant? wierd...

    Do you have long strings (AnsiStings) off by default in that project?

    If so, then the default string is a ShortString (only 255 characters).

    Not sure about the constant issue though...

    cheers,
    Paul

  3. #3

    Re: Undesired Constant String

    Quote Originally Posted by paul_nicholls
    Considered a constant? wierd...

    Do you have long strings (AnsiStings) off by default in that project?

    If so, then the default string is a ShortString (only 255 characters).

    Not sure about the constant issue though...

    cheers,
    Paul
    I don't see any options to turn them on/off. Compiling with the latest public release of FPC (2.2.4) from the command line yields the same error, "Error: Constant strings can't be longer than 255 chars"

    (Happens when assigning a string to rooms[0].w, to be more exact).

    I figured I should also mention that while my first post shows TRoom as being a class, it was originally a record and I've changed it back to a record. (I try random things sometimes, quite often with no real reasoning behind it.)

  4. #4

    Re: Undesired Constant String

    You can use
    [pascal]{$H+}[/pascal]

    and

    [pascal]{$H-}[/pascal]

    to turn on/off huge-strings respectively in your code

    I always add in {$H+} at the top of my units/project file to make sure like so:

    [pascal]Unit state_playgame;
    {$IFDEF fpc}
    {$mode delphi}
    {$ENDIF}
    {$H+}
    Interface

    Uses[/pascal]

    cheers,
    Paul

  5. #5

    Re: Undesired Constant String

    Thanks, but that did not fix the problem. I even tried making a local variable, which gave the same error.

  6. #6

    Re: Undesired Constant String

    I think you need to show us your actual code so we can help you better, like the class, and how it is being used.

    cheers,
    Paul

  7. #7

    Re: Undesired Constant String

    This is the unit in its entirety: http://pastebin.com/m7e4891a6
    Look for procedure LoadArea1

  8. #8

    Re: Undesired Constant String

    Thanks chief

    I will have a quick look for you

    EDIT: it compiles just fine for me under Lazarus 0.9.28.2 (fpc 2.2.4) after I quickly added the unit to an existing project...

    It also compiles using Delphi 6 too.

    Here is the screenshot from Delhi 6:



    EDIT#2 OOPS! I didn't notice your commented out line at the bottom of the code...sorry!!

    Ok, now I get this error (Delphi - seems a bit more descriptive than your fpc error):

    "String literals may have at most 255 elements"

    In Delphi at least (and guessing fpc too), this means you need to break up string literals (or constants) into 255 or smaller chunks like so:

    [pascal] rooms[0].w := '2[&]2[&]You turn your head to the west. The immense iron bars of the cell door are impassable. The door is locked.[&]You slide the crudely made key into the lock. As you turn the bone key, it snaps in half. '+
    'Luckily for you, the door was unlocked just before the key broke.';
    [/pascal]

    I hope this helps

    BTW, I'm not sure what the "2[&]" parts are for in the string...some sort of commands that you interpret via code?

    cheers,
    Paul

  9. #9

    Re: Undesired Constant String

    Quote Originally Posted by paul_nicholls
    Ok, now I get this error (Delphi - seems a bit more descriptive than your fpc error):

    "String literals may have at most 255 elements"

    In Delphi at least (and guessing fpc too), this means you need to break up string literals (or constants) into 255 or smaller chunks like so:

    [pascal] rooms[0].w := '2[&]2[&]You turn your head to the west. The immense iron bars of the cell door are impassable. The door is locked.[&]You slide the crudely made key into the lock. As you turn the bone key, it snaps in half. '+
    'Luckily for you, the door was unlocked just before the key broke.';
    [/pascal]

    I hope this helps

    BTW, I'm not sure what the "2[&]" parts are for in the string...some sort of commands that you interpret via code?

    cheers,
    Paul
    Yes! Splitting it up like that worked perfectly. Now if only fpc could adopt more descriptive errors like Delphi's

    (And yes, I plan on interpreting it via code. See this line: "// room[&]key[&]Descrip[&]Enter key descrip". That's a note to self to remember how it's structured. It's mostly for the door/key system, but I think I'll expand it later as well.)

  10. #10

    Re: Undesired Constant String (resolved)

    Glad I could help, and good luck with your entry

    cheers,
    Paul

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •