Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-07

Constant strings can't be longer than 255 chars

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I've got a few functions defined with 'const' string parameters. When I tried to pass a large string, I got the following error message. Why is that? I thought string type can hold as much as the memory you have in your system. I am using the following compiler mode in all my units: {$mode objfpc}{$H+}

------------------------------
filedialog.lpr(142,56) Error: Constant strings can't be longer than 255 chars filedialog.lpr(260) Fatal: There were 1 errors compiling module, stopping ------------------------------

Here is the methods I defined... It's the AText parameter that I'm trying to pass large text 500-1000 characters.

    class function Critical(const ATitle: string; const AText: string;
AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton: TfpgMsgDlgBtn =
mbNoButton): TfpgMsgDlgBtn;
    class function Information(const ATitle: string; const AText:
string; AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton:
TfpgMsgDlgBtn = mbNoButton): TfpgMsgDlgBtn;
    class function Question(const ATitle: string; const AText: string;
AButtons: TfpgMsgDlgButtons = [mbYes, mbNo]; ADefaultButton:
TfpgMsgDlgBtn = mbNo): TfpgMsgDlgBtn;
    class function Warning(const ATitle: string; const AText: string;
AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton: TfpgMsgDlgBtn =
mbNoButton): TfpgMsgDlgBtn;

And this is how I normally call those functions... The examples below work, but if AText contained more than 255 characters, it doesn't compile. I really don't see the problem? Is the only way around this problem, by first defining a local variable of type String and then passing the variable? Not that I can see a difference between that and what I'm trying to do!

  TfpgMessageDialog.Information('Some Information...', 'And this is
where the text goes.', [mbOK], mbNoButton);
  TfpgMessageDialog.Question('Some Question...', 'Did everything work
okay?', mbYesNo, mbNoButton);

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Graeme Geldenhuys
to Graeme Geldenhuys

I forgot to mention, I'm using FPC 2.2.0 under Linux (32bit system).

Graeme.

2008/7/7 Graeme Geldenhuys :

Show quoted text 54 lines
Hi, I've got a few functions defined with 'const' string parameters. When I tried to pass a large string, I got the following error message. Why is that? I thought string type can hold as much as the memory you have in your system. I am using the following compiler mode in all my units: {$mode objfpc}{$H+} ------------------------------ filedialog.lpr(142,56) Error: Constant strings can't be longer than 255 chars filedialog.lpr(260) Fatal: There were 1 errors compiling module, stopping ------------------------------ Here is the methods I defined... It's the AText parameter that I'm trying to pass large text 500-1000 characters. class function Critical(const ATitle: string; const AText: string; AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton: TfpgMsgDlgBtn = mbNoButton): TfpgMsgDlgBtn; class function Information(const ATitle: string; const AText: string; AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton: TfpgMsgDlgBtn = mbNoButton): TfpgMsgDlgBtn; class function Question(const ATitle: string; const AText: string; AButtons: TfpgMsgDlgButtons = [mbYes, mbNo]; ADefaultButton: TfpgMsgDlgBtn = mbNo): TfpgMsgDlgBtn; class function Warning(const ATitle: string; const AText: string; AButtons: TfpgMsgDlgButtons = [mbOK]; ADefaultButton: TfpgMsgDlgBtn = mbNoButton): TfpgMsgDlgBtn; And this is how I normally call those functions... The examples below work, but if AText contained more than 255 characters, it doesn't compile. I really don't see the problem? Is the only way around this problem, by first defining a local variable of type String and then passing the variable? Not that I can see a difference between that and what I'm trying to do! TfpgMessageDialog.Information('Some Information...', 'And this is where the text goes.', [mbOK], mbNoButton); TfpgMessageDialog.Question('Some Question...', 'Did everything work okay?', mbYesNo, mbNoButton); Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/
Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/
Jonas Maebe
to Graeme Geldenhuys: I've got a few functions defined with 'const' string parameters. When I tried to pass a…
Graeme Geldenhuys wrote
I've got a few functions defined with 'const' string parameters. When I tried to pass a large string, I got the following error message. Why is that?

Because the scanner only handles shortstrings for speed reasons. You can construct longer strings by concatenating multiple shorter strings (they will be concatenated at compile time).

So

someproc('this string can be 255 characters' + 'and this one as well');

Jonas

Florian Klaempfl
to Jonas Maebe
Show quoted text 10 lines
On 07 Jul 2008, at 18:26, Graeme Geldenhuys wrote: > I've got a few functions defined with 'const' string parameters. When > I tried to pass a large string, I got the following error message. Why > is that? Because the scanner only handles shortstrings for speed reasons. You can construct longer strings by concatenating multiple shorter strings (they will be concatenated at compile time).

Maybe we should fix this and introduce a patternl (for long) for cstring, there are only a few places in the compiler where this used.

Graeme Geldenhuys
to Jonas Maebe: Because the scanner only handles shortstrings for speed reasons. You can construct longer…

2008/7/7 Jonas Maebe :

Show quoted text 6 lines
Because the scanner only handles shortstrings for speed reasons. You can construct longer strings by concatenating multiple shorter strings (they will be concatenated at compile time). someproc('this string can be 255 characters' + 'and this one as well');

Strange, but I don't know what the compiler everything does... So I can live with your solution. :) Thanks for the quick response.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/