Hmm, I wrote code for an article that may be useful to you a while back. Bear in mind that the code was just an example to demonstrate what the article talked about, but still...

EDIT: Direct link to the example code is here and you want to look at PlayingGameState.pas (or something like that).