How to copy cookies in Indy 10

178 Views Asked by At

I'm using Indy 10 in Delphi 7. I have a TidCookieManager in a main form and I wish to copy its cookies over to another cookie manager in a separate thread, this thread obviously has access to the main form.

How do I copy those cookies?

Thanks,

David

1

There are 1 best solutions below

0
Remy Lebeau On

TIdCookieManager has a public CookieCollection property of type TIdCookies which provides access to the actual cookies. The cookies of one TIdCookies can be directly copied to another TIdCookies via its Assign() or AddCookies() method, eg:

// clears the dest collection before then copying cookies to it...
CookieMgrInWorkerThread.CookieCollection.Assign(CookieMgrInMainThread.CookieCollection);
// does not clear the dest collection before copying cookies to it...
CookieMgrInWorkerThread.CookieCollection.AddCookies(CookieMgrInMainThread.CookieCollection);

Either way, TIdCookies is thread-safe, as it uses an internal TMultiReadExclusiveWriteSynchronizer during read/write operations.