(06-03-2020, 02:04 PM)Alan.F Wrote:Code:procedure TForm1.IdHTTPServer1SessionStart(Sender: TIdHTTPSession);
begin
Sender.Content.Create;
Sender.Content.AddPair('phase','1');
end;
First, that is not the correct syntax to use to create an object.
Second, you don't need to create the Content object manually anyway, as it is already created for you when the TIdHTTPSession object is created. So just get rid of that line completely:
Code:
procedure TForm1.IdHTTPServer1SessionStart(Sender: TIdHTTPSession);
begin
Sender.Content.AddPair('phase','1');
end;
(06-03-2020, 02:04 PM)Alan.F Wrote:Code:procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
phase : string;
begin
if ARequestInfo.Session <> nil then phase := ARequestInfo.Session.Content.Values['phase'];
....
end;
That code is fine. You can freely access and set the ARequestInfo.Session.Content and AResponseInfo.Session.Content as needed.
(06-03-2020, 02:04 PM)Alan.F Wrote: Concerning the threadlist, with IdHTTPServer1.SessionList I don't see how I can lock the list. Please can you help me ?
As I told you earlier, the TIdHTTPServer.SessionList property is a TIdHTTPCustomSessionList, which points to a TIdHTTPDefaultSessionList by default, and TIdHTTPDefaultSessionList is where the TThreadList resides, not in TIdHTTPCustomSessionList. So, you will have to type-cast the TIdHTTPServer.SessionList in order to access the TThreadList, eg:
Code:
var
List: TIdHTTPSessionList;
with (IdHTTPServer1.SessionList as TIdHTTPDefaultSessionList).SessionList do
begin
List := LockList;
try
// use List as needed...
finally
UnlockList;
end;
end;