I guess httpal didn't fully understand what we have explained to him/her. Let's me try to explain using easier to understand words.
In the old days programming, the program flow is easier to understand because it runs straight from upper to lower (except looping, branching, sub routines/functions/procedures calling).
In nowadays, the flow is a bit harder to predict (for beginners) because the software (Lazarus, etc) is using event driven programming concept. What is it? Follow this link below if want to know more:
https://en.wikipedia.org/wiki/Event-driven_programminghttpal's code should be no problem if being used on non-event-driven programming. So, what's wrong? He/she failed to understand how event driven application works. The fix is not simply using free/terminate/halt/close or whatever to make the program stop.
Event driven programming is usually used for creating GUI applications. If you don't know what a GUI application is, in simple words, it is a program that has a mainform which usually has some buttons for users to click.
This is the simplified version how running normal GUI application will flow:
User run the program > initialize application data > initialize forms > forms' onCreate are processed > components' onCreate (in the form) are processed > displaying mainform > mainform's onActivate is processed > ...
This is the simplified version how running httpal's code will flow:
User run the program > initialize application data > initialize forms > forms' onCreate are processed > some process ... displaying showmessage ... quit > ...
Pay attention on the flow above. The form is just in the creation process and haven't fully created. In my opinion the name "FormCreate" event should be renamed as "FormBeforeCreation".
Because the form haven't 'really' created, you should not tell the program to quit or do some paintings (ShowMessage). As far as I know ShowMessage can only be used if the program has finished the loading process, that is in "mainform's onActivate".
So, what are the solutions if we want to make httpal's code works?
Solution1
Don't make it a GUI application. By doing so, it will become less event driven (it is still event driven actually).
Solution2
Using TTimer to make sure the mainform has fully loaded before processing the 'real' process.
Solution3
Follow molly's suggestion: disable form auto-creation and add some extra code. I haven't tried but it sounds possible. This Solution3 is a bit harder, I think. Similarly, I will suggest move httpal's code to the application main loop (in the *.lpr file).
Solution4
Add a button on the form and move the code to the button onClick event.
Solution5
I never tried, but it should work. Move the code to form's onActivate event (instead of FormCreate).
Solution6
Don't use ShowMessage. I'm not sure, but you can try. So remove the line that has ShowMessage. To have ShowMessage running correctly, it requires the application to fully loaded.
Hope you can understand.