Recent

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

tygraphics

  • New Member
  • *
  • Posts: 15
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: 5129
  • My goal: build my own game engine using Lazarus

tygraphics

  • New Member
  • *
  • Posts: 15
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: 1232
    • 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.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

tygraphics

  • New Member
  • *
  • Posts: 15
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: 1232
    • 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.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Kays

  • Hero Member
  • *****
  • Posts: 569
  • 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: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

tygraphics

  • New Member
  • *
  • Posts: 15
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