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

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain 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" 了; 欢迎指正!