PDA

View Full Version : Help with custom type



erikphilips
12-11-2003, 09:10 AM
tGameStatus = (gsLoadSettings, gsCreateDisplay, gsStart, gsTesting);

gameStatus: tGameStatus;
gameStatusNext: tGameStatus;




if (gameActive and gameFocus) then
try
case gameStatus of
(gsLoadSettings):
begin
if (gameStatusNext = nil) then
gameStatus := gsCreateDisplay;
end;
(gsCreateDisplay):
begin
gameDisplay := cGraphics.Create(handle);
end;
else
gameUtils.dialogFatal('Unknown Game Status!');
application.Terminate;
end;
end;


Anyway, it obviously fails at if gameStatusNext, if i have not assigned GameStatusNext, what is it? How do i see if there is a next status?

cairnswm
12-11-2003, 09:14 AM
Enumerated types are always Ordinal (you can do Ord(Type)) which means they are effectivly integer values. The first value in the list is 0 (zero) and it will normally be the default value. Add an additional value at the start of the enumerated type of gtNone and check for gtNone instead of Null.

erikphilips
12-11-2003, 09:33 AM
That sounds like a good idea. I see what you mean. Thanks.

Alimonster
12-11-2003, 09:55 AM
Yes, I'd be inclined to add a gsNone there as a default.

You can also consider using the High and Low functions, which will return the highest and lowest types:

if GameStatus = High(TGameStatus) then
// last one
else
// not last one

Since you're on the subject, I have an article on states (http://www.alistairkeys.co.uk/states.shtml) on my (becoming a little neglected) web site.

erikphilips
12-11-2003, 11:56 PM
Thats funny, you wrote a whole tutorial about what I thought would be a good idea :lol:. Yeah now I'm gonna write a class. FINITO!