Sign in Join

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

Mailing lists / fpc-pascal / 2006-10

TypInfo Error: type identifier not allowed here

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Why do I get this error?
/tiOPF/UnitTests/Common/tiDUnitUtils.pas(231,32) Error: type identifier not allowed here

It works on other enumerated declarations, but not on this one. I am pretty sure this code worked before, as I have been using tiOPF under FPC since December 2005. I marked the location of the error with a comment in the code below.

procedure TtiTestCase.CheckObjectState(
  pObjectState: TPerObjectState;
  pData: TtiObject;
  const pMessage: string = '');
begin
  Assert(pData.TestValid, cTIInvalidObjectError);
  Check(pObjectState = pData.ObjectState,
          'ObjectState: Expected <' +
          GetEnumName(TypeInfo(TPerObjectState), Ord(pObjectState)) +
//  error occurs here               ---^---
          '> but got <' +
          pData.ObjectStateAsString +
          '> on ' + pData.ClassName + '. ' + pMessage);
end;

where TPerObjectState is declared as follows:

  TPerObjectState = (
                      posEmpty,
                      posPK,
                      posCreate,
                      posUpdate,
                      posDelete,
                      posDeleted,
                      posClean
                     ) ;

I am using FPC 2.1.1 (r4642) under Linux (kernel 2.6) on Intel P4 processor.

Regards,
- Graeme -

There's no place like 127.0.0.1
Graeme Geldenhuys
to Graeme Geldenhuys

Yet if I don't use the GetEnumName inline, it works!?!?

For example, I call GetEnumName and store the result in a string variable, and then use it in the Check() method.

Oh, and Check() is define as follows;
    class procedure Check(pValue: boolean; pMessage: string = '');
procedure TtiTestCase.CheckObjectState(
  pObjectState: TPerObjectState;
  pData: TtiObject;
  const pMessage: string = '');
var
  objstate: string;
begin
  Assert(pData.TestValid, cTIInvalidObjectError);
  objstate := GetEnumName(TypeInfo(TPerObjectState), Ord(pObjectState));

Check(pObjectState = pData.ObjectState,
'ObjectState: Expected <' +

           {$IFDEF FPC}
              {$Note Find out why TypeInfo doesn't work in this case! It can't
                be used directly??? }
           {$ENDIF}
          objstate +
          '> but got <' +
          pData.ObjectStateAsString +
          '> on ' + pData.ClassName + '. ' + pMessage);

end;

Why can I not use GetEnumName inline?

Regards,
- Graeme -

Graeme Geldenhuys wrote 48 lines
Why do I get this error? /tiOPF/UnitTests/Common/tiDUnitUtils.pas(231,32) Error: type identifier not allowed here It works on other enumerated declarations, but not on this one. I am pretty sure this code worked before, as I have been using tiOPF under FPC since December 2005. I marked the location of the error with a comment in the code below. procedure TtiTestCase.CheckObjectState( pObjectState: TPerObjectState; pData: TtiObject; const pMessage: string = ''); begin Assert(pData.TestValid, cTIInvalidObjectError); Check(pObjectState = pData.ObjectState, 'ObjectState: Expected <' + GetEnumName(TypeInfo(TPerObjectState), Ord(pObjectState)) + // error occurs here ---^--- '> but got <' + pData.ObjectStateAsString + '> on ' + pData.ClassName + '. ' + pMessage); end; where TPerObjectState is declared as follows: TPerObjectState = ( posEmpty, posPK, posCreate, posUpdate, posDelete, posDeleted, posClean ) ; I am using FPC 2.1.1 (r4642) under Linux (kernel 2.6) on Intel P4 processor. Regards, - Graeme - -- There's no place like 127.0.0.1
There's no place like 127.0.0.1