Cookie ?

Hello devs,


Is it possible to set/get cookies ?

Have a look at the unit WEBLib.Cookies that offers the TCookies collection for managing cookies.

Is there any documentation somewhere ?


And "WEBLib.Cookies" in uses give me an error at design time (but it compiles successfully).

Sorry to insist, but I need this, there is no documentation, nothing else on the forum, and nothing on th web.

What exact error do you get at design-time, as WEBLib.Cookies is unit that has the TCookies collection class and not really design-time behavior.

"Cannot resolve unit name 'WEBLib.Cookies'"


I put it in global uses (at the top of the source code). 

Other WEBLib uses (Login, REST, DB,Forms,...) are OK.

You should have WEBLib.Cookies.pas in the source subfolder "Component Library Source"  of your TMS WEB Core install and this folder should be in your IDE library path. Can you double check this.

The file is in the subfolder, but I hadn't the folder in the IDE library path. I added it, but nothing changed.


However, it compiles correctly, so I can use it. My priority is to know how it works. Do you have any documentation ?
Hi Mathieu,

I used it this way...

uses WebLib.Cookies;
procedure TMainForm.btn_SetCookieClick(Sender: TObject);
var
  Cookies: TCookies;
begin
  Cookies := TCookies.Create;
  Try
    Cookies.Add('mycookie','789', Now + 3);
    Cookies.SetCookies;
  Finally
    Cookies.Free;
  End;
end;

Thank you very much Feichtenschlager, this is exactly what I expected !


If that can help someone else, this is my code :


function PR_getCookie: string;
var
  VLOcookies: TCookies;
  VLOcookie: TCookie;
begin
  Result := '';
  VLOcookies := TCookies.Create;
  try
    VLOcookies.GetCookies;
    VLOcookie := VLOcookies.Find('name');
    if Assigned(VLOcookie) then
    begin
      Result := VLOcookie.Value;
    end;
  finally
    VLOcookies.Free;
  end;
end;


procedure PR_setCookie(p_value: string);
var
  VLOcookies: TCookies;
begin
  VLOcookies := TCookies.Create;
  try
    VLOcookies.Add('name', p_value);
    VLOcookies.SetCookies;
  finally
    VLOcookies.Free;
  end;
end;


procedure PR_deleteCookie;
var
  VLOcookies: TCookies;
begin
  VLOcookies := TCookies.Create;
  try
    VLOcookies.GetCookies;
    VLOcookies.Delete('name');
    VLOcookies.SetCookies;
  finally
    VLOcookies.Free;
  end;
end;


I still have errors at design-time. I tried to had the  "Component Library Source" in the library path called "Path", and to create a new one called "TMS" or "WEBCORE". 


The folder (and files) is stored in my local machine.

what exact error?

Same as before :

"Cannot resolve unit name 'WEBLib.Cookies'"
And :
"Identifier not found 'TCookies'"
"Identifier not found 'TCookie'"
etcetera
I cannot reproduce this:

https://snipboard.io/xlea96.jpg

The only reason I can see for this is that your IDE library path is not setup correct.
You can verify this yourself. Search WEBLIB.Cookies.pas in Component Library Source. You should find this file and you should make sure the path where this file is, is in your IDE library path.

I think too, but all is OK :

https:///snipboard.io/CyWKae.jpg
https://snipboard.io/iny2h6.jpg

Library path "PATH" has the folder deifned too.

The Delphi IDE library path is in the IDE under Tools, Options, Delphi Options, Library 


This does NOT concern a system path!

My bad, you're right. Thank you very much !


All is working fine now.