我在TMS Web Core中有一个简单的项目.
我想在运行时在我的TWebHTMLDiv
组件内的循环中创建一系列按钮,并根据每个按钮的循环索引调用德尔菲myFunc
函数.
德尔菲端的myFunc
函数接受输入并发送带有按钮索引的ShowMessage
.
我的问题是我不知道如何从模板端调用带有参数的函数
我的单位代码:
unit Unit1;
interface
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, WEBLib.WebCtrls;
type
TForm1 = class(TWebForm)
WebHTMLDiv1: TWebHTMLDiv;
procedure WebFormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure myFunc(ACode: string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.myFunc(ACode: string);
begin
ShowMessage(ACode);
end;
procedure TForm1.WebFormShow(Sender: TObject);
var
i: integer;
begin
WebHTMLDiv1.HTML.Text := '';
for i := 1 to 5 do
WebHTMLDiv1.HTML.Text := WebHTMLDiv1.HTML.Text +
'<button type="button" onclick="myFunc(' + i.ToString +
')" class="btn btn-primary btn-sm">BtnNum' + i.ToString + '</button>';
end;
end.
我的HTML模板代码:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>TMS Web Project</title>
<style>
</style>
</head>
<body>
<div id = "htmlDiv">
</div>
</body>
</html>