Sign in Join

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

Mailing lists / lazarus / 2011-06

[again] Can't take the address of constant expressions

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

John Repucci

I was testing the below code from the fpc documentation and I get the "Can't take the address of constant expressions" error, with the cursor positioned just after "(S)" in the 2nd WriteLn statement.

I do not understand how to fix this. I did search for the error, but it none of it makes sense.
I'll solve my issue another way, but I'm wondering if this example should be fixed.

0.9.31-30142, 2.4.2, win32-Vista

Any suggestions?

source:
http://www.freepascal.org/docs-html/rtl/sysutils/ansiextractquotedstr.html

Program Example51;
{ This program demonstrates the AnsiQuotedStr function }
Uses sysutils;
Var S : AnsiString;
Begin
 S:='He said "Hello" and walked on';
 S:=AnsiQuotedStr(Pchar(S),'"');
 Writeln (S);
 Writeln(AnsiExtractQuotedStr(Pchar(S),'"'));
End.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110609/af939b83/attachment.html>

Reply by email

Unknown author
to John Repucci
John Repucci wrote 12 lines
I was testing the below code from the fpc documentation and I get the "Can't take the address of constant expressions" error, with the cursor positioned just after "(S)" in the 2nd WriteLn statement. I do not understand how to fix this. I did search for the error, but it none of it makes sense. I'll solve my issue another way, but I'm wondering if this example should be fixed. 0.9.31-30142, 2.4.2, win32-Vista Any suggestions?

The following will work:

Program Example51;
{ This program demonstrates the AnsiQuotedStr function }
Uses sysutils;
Var
   S : AnsiString;
   P : PChar;
Begin
  S:='He said "Hello" and walked on';
  P:=Pchar(S);
  S:=AnsiQuotedStr(P,'"');
  Writeln (S);
  P:=Pchar(S);
  Writeln(AnsiExtractQuotedStr(P,'"'));
End.

The cause of the error may be that the signature of the AnsiExtractQuotedStr has changed (the first parameter has been made a var) or else the compiler has become more strict in it's checking of the parameters.

I have corrected the example in the docs.

Michael.

Show quoted text 18 lines
source: http://www.freepascal.org/docs-html/rtl/sysutils/ansiextractquotedstr.html Program Example51; { This program demonstrates the AnsiQuotedStr function } Uses sysutils; Var S : AnsiString; Begin S:='He said "Hello" and walked on'; S:=AnsiQuotedStr(Pchar(S),'"'); Writeln (S); Writeln(AnsiExtractQuotedStr(Pchar(S),'"')); End.

Reply by email