Board index » delphi » Error in Delphi Syntax checking.

Error in Delphi Syntax checking.

There seems to be an error in the Delphi parser.  I can't index a string unless
it is declared a string variable.

var
  s  : string;
begin
  s[2] := 'a' ;                    { this works }
  Button1.Caption[ 2 ] := 'a';    { error! }
end ;

According to the syntax, this should work.  Am I overlooking something.  I
need to do this using TStringField.  My workaround is to assign
TStringField.Value to a string, change it, and assign it back.  This works but
seems a screwy way to do it.

Lance Hirsch
lhir...@ibm.net

 

Re:Error in Delphi Syntax checking.


In article 2...@news-s01.ny.us.ibm.net, lhir...@ibm.net writes:

Quote
>var
>  s  : string;
>begin
>  s[2] := 'a' ;                    { this works }
>  Button1.Caption[ 2 ] := 'a';    { error! }
>end ;

>According to the syntax, this should work.  Am I overlooking something.  I
>need to do this using TStringField.  My workaround is to assign
>TStringField.Value to a string, change it, and assign it back.  This works but
>seems a screwy way to do it.

Probably because Caption is a Property.  Therefore it may theoretically do anything
in order to write the caption.

HTH

Ray Cramer
R...@Pol.ac.uk

Re:Error in Delphi Syntax checking.


Quote
>There seems to be an error in the Delphi parser.  I can't index a string unless
>it is declared a string variable.

This is as designed.

Quote
>var
>  s  : string;
>begin
>  s[2] := 'a' ;                    { this works }

Of course...

Quote
>  Button1.Caption[ 2 ] := 'a';    { error! }
>According to the syntax, this should work.  Am I overlooking something.  I
>need to do this using TStringField.  

Can't do this to properties.

Quote
>My workaround is to assign
>TStringField.Value to a string, change it, and assign it back.  This works but
>seems a screwy way to do it.

This is the only way to do it.

Cheers
Wade

Other Threads