Way 1:
Create temporary file with that code and call the compiler to compile this file, and if successful, execute it.
Way 2:
Embed a Pascal interpreter capable of executing the language subset you want (AFAIK currently no interpreter implements all Object Pascal constructs, esp. those which are specific to Free Pascal).