I'm sorry if I ask a dumb question... do you know how to do normal file handling in Delphi? If you're getting a 500 error then your CGI is probably excepting, you're going to need to find out what the exception message is before you go any further.

Simplest way would be to create a log file, and wrap the connection activation in a try..except block, capture the exception and write the message out to your log file. Let me know if you'd like some example code for this.

Without knowing what's going on when you try the connect, it's a complete guessing game.