Hello,

I have a lot of constant strings and some array of records that should be initialized in one field with one of this entries, so I found two solutions, one is create a symbol for each string, something like:

const
  TMyStringSymbol='String one';

But also I need to be able to enumerate all of them at runtime, so I wrote an array and initialize it at compile time (this also produces less symbol pollution for the compiler):

const
  TMyStrings: array [0..1] of pchar = (
    'String One','String Two');

As I need this names in other places I try to create a record and initialize it at runtime using the pchar of the previous array, and here is the problem:

-----------------------
program testpossiblebug;

type
  TFirstRecord=record
    Ident: pchar;
  end;

const
  TSomePcharArray: array [0..1] of pchar = ( 'pcharONE','pcharTWO');

{$DEFINE THISDONTCOMPILE}

  TConstRecord: TFirstRecord = (
  {$IFDEF THISDONTCOMPILE}
    Ident: TSomePcharArray[1]
  {$ELSE}
    Ident: @TSomePcharArray[1]
  {$ENDIF}
  );

var
  R: TFirstRecord;

begin
  R:=TConstRecord;
  {$IFDEF THISDONTCOMPILE}
  writeln(R.Ident);
  {$ELSE}
  writeln(PPchar(R.Ident)^);
  {$ENDIF}
end.
------------------------

This does not compile and outputs the funny error in the subject. I think it should compile as information is static and previously defined, but if it is indeed an error by my side maybe the error message should be a bit different :-?

To test the example, define or undefine the "THISDONTCOMPILE", with it defined it does not compile, without it it compiles and the modified writeln shows the expected pchar string.

Should I report it ?

--

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to