惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
U
Unit 42
腾讯CDC
D
Docker
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
I
InfoQ
Jina AI
Jina AI
爱范儿
爱范儿
宝玉的分享
宝玉的分享
博客园 - Franky
G
Google Developers Blog
P
Proofpoint News Feed

博客园 - 万一

关于内存数据与 JSON 高亮 TRichEdit 当前行 使用 IntraWeb (45) - 活用 IntraWeb 使用 IntraWeb (44) - 测试读取 SqLite (三) 使用 IntraWeb (43) - 测试读取 SqLite (二) 使用 IntraWeb (42) - 测试读取 SqLite (一) 使用 IntraWeb (41) - 数据控件速查 使用 IntraWeb (40) - 自定义 Session 数据 使用 IntraWeb (39) - THttpRequest、THttpReply 使用 IntraWeb (38) - TIWAppForm、TIWForm、TIWBaseHTMLForm、TIWBaseForm 使用 IntraWeb (37) - TIWApplication 使用 IntraWeb (36) - TIWServerControllerBase 使用 IntraWeb (35) - TIWJQueryWidget 使用 IntraWeb (34) - TIWAJAXNotifier 使用 IntraWeb (32) - Url 映射与 THandlers 使用 IntraWeb (31) - IntraWeb 的 Xml 操作使用的是 NativeXml 使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache 使用 IntraWeb (29) - 基本控件之 TIWAutherList、TIWAutherINI、TIWAutherEvent 使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm
使用 IntraWeb (33) - Cookie
万一 · 2014-06-24 · via 博客园 - 万一

在 IW.HTTP.Cookie 单元提供有两个相关类: THTTPCookie、TCookieList; 另外 IWServerController 还有一个 CookieOptions 选项.

但实用起来一般用不到它们.


测试:



{读取 Cookie; 放在 OnCreate 中不太合适, 因为在切换页面时, 如果窗口没被销毁时 OnCreate 也不执行}
procedure TIWForm1.IWAppFormRender(Sender: TObject); //OnRender
begin
  IWEdit1.Text := WebApplication.Request.CookieFields.Values['IWEdit1'];
end;

{写入 Cookie; 应该把它放在什么事件中呢? 很伤脑筋, 譬如 OnDestroy 就不大合适, 因为在关掉页面时它并不执行}
procedure TIWForm1.IWEdit1AsyncChange(Sender: TObject; EventParams: TStringList); //IWEdit1.OnAsyncChange
begin
  WebApplication.Response.Cookies.AddCookie('IWEdit1', IWEdit1.Text, '', Now+30); //参数 1: Cookie 名;
                                                                                  //参数 2: Cookie 值;
                                                                                  //参数 3: 有效范围, 空表示当前站点;
                                                                                  //参数 4: 有效时间, Now+30 表示 30 天内有效
end;

{遍历 Cookie}
procedure TIWForm1.IWButton1Click(Sender: TObject);
var
  str: string;
begin
  for str in WebApplication.Request.CookieFields do IWMemo1.Lines.Add(str);
end;

{关闭窗口}
procedure TIWForm1.IWButton2Click(Sender: TObject);
begin
  WebApplication.Terminate;
end;