Recent

Author Topic: Using ANSI Strings to avoid exceeding string limit at compile  (Read 458 times)

tygraphics

  • New Member
  • *
  • Posts: 10
Using ANSI Strings to avoid exceeding string limit at compile
« on: September 29, 2020, 10:36:01 pm »
When I try to compile my pascal code that has a string longer than 255 char I get the following error:
VeryLongNames_G.p(24,250) Fatal: String exceeds line

Is there a setting or flag that allows the compiler to accommodate strings that are greater than 255 char?

Thanks!

Handoko

  • Hero Member
  • *****
  • Posts: 3868
  • My goal: build my own game engine using Lazarus

tygraphics

  • New Member
  • *
  • Posts: 10
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #2 on: September 29, 2020, 10:49:02 pm »
I placed the {$H+} on the main program but got the same error. Does it have to be added to any units that have long strings?
After adding {$H+} to the unit with the long strings and it compiled!
Thanks for the help!
« Last Edit: September 29, 2020, 10:56:15 pm by tygraphics »

jwdietrich

  • Hero Member
  • *****
  • Posts: 1142
    • formatio reticularis
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #3 on: September 29, 2020, 10:52:43 pm »
I placed the {$H+} on the main program but got the same error. Does it have to be added to any units that have long strings?

Yes, in the beginning before declaring or using any strings (but after mode directives).
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

tygraphics

  • New Member
  • *
  • Posts: 10
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #4 on: September 29, 2020, 11:01:00 pm »
I'm generating the unit files as I parse through a collection of hundreds of components.
Is there any harm in adding the {$H+} as a standard part of all my unit files?

jwdietrich

  • Hero Member
  • *****
  • Posts: 1142
    • formatio reticularis
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #5 on: September 29, 2020, 11:07:53 pm »
I'm generating the unit files as I parse through a collection of hundreds of components.
Is there any harm in adding the {$H+} as a standard part of all my unit files?

Probably not, but if your code contains mode directives {$H+} may be deactivated again (with the exception of {$MODE DELPHI}, which implies {$H+}).
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

Kays

  • Full Member
  • ***
  • Posts: 216
  • Whasup!?
    • KaiBurghardt.de
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #6 on: September 30, 2020, 12:43:36 am »
[…] Is there any harm in adding the {$H+} as a standard part of all my unit files?
You can write your own fpc.cfg and place -Sh (the command line option to enable ANSI strings by default) in it.
Yours Sincerely
Kai Burghardt

lucamar

  • Hero Member
  • *****
  • Posts: 3084
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #7 on: September 30, 2020, 12:51:16 pm »
When I try to compile my pascal code that has a string longer than 255 char I get the following error:
VeryLongNames_G.p(24,250) Fatal: String exceeds line

For completeness sake, note also that the error doesn't normally mean that the string is too long but that it is not terminated in the same line, usually meaning that you have code like:
Code: Pascal  [Select][+][-]
  1. somestring := 'This string isn't well formed';
instead of:
Code: Pascal  [Select][+][-]
  1. somestring := 'This string isn''t well formed';
(note the doubled single quotes in "isn''t") or that you forgot  to close the string (i.e. the last single quote is missing).

HTH :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

tygraphics

  • New Member
  • *
  • Posts: 10
Re: Using ANSI Strings to avoid exceeding string limit at compile
« Reply #8 on: September 30, 2020, 02:29:48 pm »
Yes, the string was malformed and that caused the error. It was malformed because of a hack I wrote many years ago that breaks long writeln statements into as many write statements as necessary to keep them under 250 char. Unfortunately in this case the chop point was in a bad location. Yesterday I fixed my code and it handled the 367 char string without error due to adding the {$H+} to the top of my generated units that could likely have a long string.

Thank you to everyone who answered! 

 

TinyPortal © 2005-2018