Not every request type uses the PostStream
property, so you have to check if the PostStream
is not nil
before you attempt to use it.
Also, TIdHTTPServer
is a multi-threaded component. Its events are triggered in worker threads, and it is not safe to access UI components from outside of the main thread, so you need to synchronize with the main thread when accessing the TMemo
.
Update: If you need to always have a PostStream
available, in older versions of Indy you can use the OnCreatePostStream
event to create your own TStream
object to use as the PostStream
. In those versions, TIdHTTPServer
manages PostStream
objects that it creates, and sometimes frees them before giving them to you, but user-defined PostStream
objects are not freed until after the request is finished being processed by you. However, in recent Indy 10 releases, there is a new OnDoneWithPostStream
event that helps control when a PostStream
gets freed for any given request, regardless of whether it is created by TIdHTTPServer
or by you (in which case, you don't need to use the OnCreatePostStream
event to extend the PostStream
's lifetime). In all versions, an unfreed PostStream
is always freed when the TIdHTTPRequestInfo
object is freed.