Discussion:
Delphi compiles with illegal character: & ???
(too old to reply)
Skybuck Flying
2008-03-14 21:07:50 UTC
Permalink
Hello,

I compiled the same project with free pascal compiler, and the free pascal
compiler warned me:

GetSystemTimeAsFileTime( &ct );

'&' illegal character.

Which raises the questions:

1. Why does Delphi compile just fine ?

2. Does the character '&' have any meaning in Delphi ?

??????????????????????????????????????????????????

Bye,
Skybuck.
Rob Kennedy
2008-03-14 22:00:35 UTC
Permalink
Post by Skybuck Flying
I compiled the same project with free pascal compiler, and the free pascal
GetSystemTimeAsFileTime( &ct );
'&' illegal character.
1. Why does Delphi compile just fine ?
Because it's perfectly legal in Delphi. Has been since at least Delphi
2005, probably Delphi 8, maybe even Delphi 7.
Post by Skybuck Flying
2. Does the character '&' have any meaning in Delphi ?
Yes. Try giving your variable a name that might normally be disallowed
and you'll see. It lets your code interoperate with .Net code from other
languages that uses "Begin" and "End" for names of functions that return
iterators, for example.

In Delphi 2005, debugger and IDE support for that wasn't perfect, but
the compiler accepted them just fine. Your mileage my vary.
--
Rob
Skybuck Flying
2008-03-14 22:14:23 UTC
Permalink
Ok,

Kinda nice, didn't know that ;) nothing in Help file too it seems ? :)

Little example to test it out: :)

// *** Begin of Test Program ***

program Project1;

{$APPTYPE CONSOLE}

{

Test &

version 0.01 created on 14 march 2008 by Skybuck Flying.

Apperently & is ment to be used to be able to declare and program with
otherwise/normally disallowed variable names and such (?)

Thanks to Rob Kennedy for explaining it.

}

uses
SysUtils;

var
&Begin : string;

begin
try
&Begin := 'This is funny';

writeln( &Begin );

except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
readln;
end.

// *** End of Test Program ***

Bye,
Skybuck.
Skybuck Flying
2008-03-14 22:17:51 UTC
Permalink
And no it was not in Delphi 7.

At least now in the version I have installed on my system:

[Error] Project1.dpr(9): Illegal character in input file: '&' ($26)

So definetly new feature :)

Bye,
Skybuck.
Jamie
2008-03-16 02:26:07 UTC
Permalink
Post by Skybuck Flying
Hello,
I compiled the same project with free pascal compiler, and the free pascal
GetSystemTimeAsFileTime( &ct );
'&' illegal character.
1. Why does Delphi compile just fine ?
2. Does the character '&' have any meaning in Delphi ?
??????????????????????????????????????????????????
Bye,
Skybuck.
the '&' simply allows you to use a reserved name as something in your code.
--
http://webpages.charter.net/jamie_5"
Loading...