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

推荐订阅源

I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 最新话题
T
Threatpost
Cisco Talos Blog
Cisco Talos Blog
The GitHub Blog
The GitHub Blog
V
V2EX
SecWiki News
SecWiki News
P
Privacy & Cybersecurity Law Blog
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
S
Security @ Cisco Blogs
Martin Fowler
Martin Fowler
Attack and Defense Labs
Attack and Defense Labs
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Register - Security
The Register - Security
Blog — PlanetScale
Blog — PlanetScale
The Last Watchdog
The Last Watchdog
T
Tor Project blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
P
Proofpoint News Feed
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
小众软件
小众软件
雷峰网
雷峰网
H
Heimdal Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
C
Cyber Attacks, Cyber Crime and Cyber Security
Webroot Blog
Webroot Blog
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
人人都是产品经理
人人都是产品经理
Hacker News: Ask HN
Hacker News: Ask HN
The Hacker News
The Hacker News
V
Vulnerabilities – Threatpost
Microsoft Security Blog
Microsoft Security Blog

博客园 - 万一

关于内存数据与 JSON 高亮 TRichEdit 当前行 使用 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 (33) - Cookie 使用 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 (45) - 活用 IntraWeb
万一 · 2014-09-17 · via 博客园 - 万一

asp.net 刚开始时, 也是拖拉控件, 但后来有了 MVC、xNext.

换个思路使用 IntraWeb 吧:
界面全部用 html+js+css 实现(有些会是用 Delphi 动态生成), 然后用 js 通过 Ajax 调用 Delphi 的方法.


测试程序要使用的模板 IWForm1.html:

1、在程序所在目录建立 Templates 文件夹, 把 IWForm1.html 放其中.
2、在程序所在目录建立 wwwroot 文件夹, 把模板中用到的 IWForm1.js 和 IWForm1.css 放其中.
3、其中的 AjaxFun1() 方法是在 IWForm1.js 中实现的; 这里两次调用参数分别是 1、2
4、{%IWLabel1%} 中的 IWLabel1 是在 Delphi 中添加的控件, 它用来返回数据结果.


IWForm1.js:

1、executeAjaxEvent 或 processAjaxEven 方法是 IntraWeb 内置的 IWLib.js 提供的; 其第三个参数决定了它将调用 Delphi 中的 IWCallBack1 方法.
2、Delphi 收到的参数将是一个 TStringList, 上面的 n 是将要传递的参数, x 是随意命名的参数标示.


IWForm1.css:

这是随意定义的; IWLABEL1 对应的是在 Delphi 添加的 IWLabel1.



//在新建 IW 主窗体上放置 IWTemplateProcessorHTML1、IWLabel1 两个控件.

unit Unit1;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, IWVCLComponent, IWBaseLayoutComponent, IWBaseContainerLayout, IWContainerLayout,
  IWTemplateProcessorHTML, IWCompLabel, Vcl.Controls, IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompButton, IWCompEdit;

type
  TIWForm1 = class(TIWAppForm)
    IWLabel1: TIWLabel;
    IWTemplateProcessorHTML1: TIWTemplateProcessorHTML;
    procedure IWAppFormCreate(Sender: TObject);
  public
    procedure DoCallBack1(EventParams: TStringList); //这是 IWForm1.js 将要调用的方法; 下面还需要通过 WebApplication.RegisterCallBack 注册一下
  end;

implementation

{$R *.dfm}

uses IW.Common.AppInfo; //获取路径需要

var gPath: string;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  LayoutMgr := IWTemplateProcessorHTML1;          //关联模板(IWForm1.html) 
  IWTemplateProcessorHTML1.RenderStyles := False; //禁用 IW 的样式设置

  WebApplication.RegisterCallBack('IWCallBack1', DoCallBack1); //注册回调; js 将通过指定名称("IWCallBack1")调用这里的 DoCallBack1 方法

  gPath := TIWAppInfo.GetAppPath + 'Data.txt'; //用于测试文件的路径

  if not FileExists(gPath) then //初始化测试文件
  begin
    with TStringList.Create do begin
      Add(DateTimeToStr(Now));
      SaveToFile(gPath, TEncoding.UTF8);
      Free;
    end;
  end;

  IWLabel1.RawText := True; //指定以 Html 的方式呈现其内容; 具有 RawText 属性的几个控件中, 发现 IWLabel1 最灵活.
  IWLabel1.StyleRenderOptions.RenderSize := False;     //既然前面已经指定了 IWTemplateProcessorHTML1.RenderStyles := False; 下面这些就应该不需要了, 但在 IE 下不行
  IWLabel1.StyleRenderOptions.RenderPosition := False;
  IWLabel1.StyleRenderOptions.RenderFont := False;
  IWLabel1.StyleRenderOptions.RenderZIndex := False;
  IWLabel1.StyleRenderOptions.RenderVisibility := False;
  IWLabel1.StyleRenderOptions.RenderStatus := False;
  IWLabel1.StyleRenderOptions.RenderAbsolute := False;
  IWLabel1.StyleRenderOptions.RenderPadding := False;
  IWLabel1.StyleRenderOptions.RenderBorder := False;
end;

procedure TIWForm1.DoCallBack1(EventParams: TStringList);
var
  List: TStringList;
  x: Integer;
begin
  x := EventParams.Values['x'].ToInteger; //获取 js 传来的参数

  List := TStringList.Create;
  List.LoadFromFile(gPath, TEncoding.UTF8);

  case x of
    1: List.Add(DateTimeToStr(Now));          //参数是 1 表示添加
    2: if List.Count > 0 then List.Delete(0); //参数是 2 表示删除
  end;

  IWLabel1.Text := List.Text.Replace(sLineBreak, '<br/>'); //呈现; 

  List.SaveToFile(gPath, TEncoding.UTF8);
  List.Free;
end;

initialization
  TIWForm1.SetAsMainForm;

end.

思路很简单, 在实践中可能会碰到一些小问题, 譬如:
1、如果真传到服务器, 那个 Data.txt 修改其属性为可写;
2、通过 executeAjaxEvent 传递中文参数时, 我在本机没发现问题, 但传到服务器不行了, 最后自己写了一个编码(js)、解码(Delphi)函数; 如果你需要可以告诉我.
不过都是小问题.

测试源文件(IW_MVC_Test.rar), 传到 "intraweb交流群 319037363" 了; 欢迎指正!