delete cookies lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- tintinux · 2025-12-15 08:26 Hi Using this code, I successfully set some cookies. I can read them later and they are as well visible in my Firefox inspector. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TWebModule.set_cookie(const aResponse: TResponse; const aName, aValue: string);var  C: TCookie;begin  C := aResponse.Cookies.Add;  C.Name := aName;  C.Value := aValue;  C.Expires := Now + 30;end; The issue is when I need to delete them. I tried : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TWebModule.delete_cookie(const aResponse: TResponse; const aName: string);var  I: Integer;begin  for I := 0 to aResponse.Cookies.Count-1 do    begin    if aResponse.Cookies[I].Name = aName then      begin    aResponse.Cookies.Delete(I);      exit;      end;    end;end; This doesn't delete the named cookie, because aResponse.Cookies.Count is equal to 0 or 1. There is only the FPWebSession cookie when CreateSession is checked. But, again, I can read all the cookies I set with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i aRequest.CookieFields.Values[aName] and show them in my internet explorer. What am I missing or doing wrong ? Thanks PS : Of course it is the same with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i aResponse.Cookies.IndexOfCookie(aName); ---------------------------------------------------------------------- Leledumbo · 2025-12-15 16:14 You should loop over aRequest.CookieFields instead, as aResponse.Cookies is meant for sending cookies as response headers, they're not connected directly unfortunately. That's why aResponse.Cookies is of type the more complex TCookies instead of simply name-value pairs like aRequest.CookieFields. To delete a cookie from browser, don't call Delete(), which is just a TCollection method not overriden to send cookie deletion. It just deletes the cookie from Cookies property. Instead, you should Add the cookie again (aResponse.Cookies.Add), but set the MaxAge property to 0. This is how the standard defines the way to delete a cookie. ---------------------------------------------------------------------- tintinux · 2025-12-19 07:53 Thank you for the tips ! If someone could explain this in the documentation, it would be great. And the best would be to override the Delete() function (at least to raise an error since it is not to be used)