1

In this demo I was trying to figure out how this code work and I stopped at this lines:

type
  TOpenWeatherRequest = (ByCoords);

How a type TOpenWeatherRequest can be defined like this ? and what the parenthesis mean ?

zac
  • 4,495
  • 15
  • 62
  • 127
  • I don't see that code in the link you provided, to know the context of your question. In either case though, you shouldn't rely on external links anyway. Please put everything needed for us to understand in the question itself. – Jerry Dodge May 19 '17 at 22:39
  • @Jerry Yes it's there in the repo. Surely you recognise an enumerated type. – David Heffernan May 19 '17 at 22:46
  • @David So we're encouraging users to post off-site resources, forcing us to to download a full repository? When did this change? And no, I didn't recognize it since it only had one value and no prefix. – Jerry Dodge May 19 '17 at 22:54
  • @Jerry No we are not. The question stands fine without any off site link. – David Heffernan May 20 '17 at 06:54

2 Answers2

5

that means an enumerable type, something as a const you can use in sets and do some logic operations with.

For example: In a chess board, you can define literal names to represents the piece:

type
  TChessPiece = (cpKing, cpBishop, cpKnight, cpRoque, cpQueen, cpPawn);

var
  Piece: TChessPiece;

Piece := cpBishop;

Look a very interesting usage in a class

type
  TChessBoard = class
  private
    FPiece: TChessPiece;
  public
    constructor Create(Piece: TChessPiece);
    procedure ShowValidMove;
  end;

implementation

procedure TChessBoard.ShowValidMove; 
begin
   case FPiece of
     cpKing: ShowMessage('Neighboard squares');
     cpBishop: ShowMessage('Diagonal squares'); 
     cpKnight: ShowMessage('L squares'); 
     cpRoque: ShowMessage('Parallel squares'); 
     cpQueen: ShowMessage('Roque AND Bishop squares'); 
     cpPawn: ShowMessage('Goes to front, captures short diagonal');
   end;
end;

Look my answer for this question, I suggest use Enumerable type to solve a Logic Matrix to hide some specific TabControls How to hide multiple tabs in TTabcontrol

Community
  • 1
  • 1
2

This is an enumerated type with a single ordinal value.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490