IntraWeb在异步事件中返回javascript 脚本

unit Unit1;

interface

{$DEFINE CODESITE}

uses {$IFDEF CODESITE}CodeSiteLogging, {$ENDIF}

Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, IWCompButton,

Vcl.Controls, IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl,

IWCompMemo, IWCompJQueryWidget, IWCompEdit;

type

TIWForm1 = class(TIWAppForm)

IWMemo1: TIWMemo;

btnMessage: TIWButton;

btnConfirm: TIWButton;

jQueryContentFiles: TIWJQueryWidget;

jQMessageExecuter: TIWJQueryWidget;

jQConfirmExecuter: TIWJQueryWidget;

procedure btnConfirmAsyncClick(Sender: TObject; EventParams: TStringList);

procedure btnMessageAsyncClick(Sender: TObject; EventParams: TStringList);

procedure IWAppFormCreate(Sender: TObject);

private

procedure AJAXConfirm(AParams: TStringList);

public

end;

implementation

{$R *.dfm}

procedure TIWForm1.btnMessageAsyncClick(Sender: TObject;

EventParams: TStringList);

begin

WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(

StringReplace(jQMessageExecuter.OnReady.Text, '@Message@', '显示一个消息对话框就是如此简单!', []));

end;

procedure TIWForm1.AJAXConfirm(AParams: TStringList);

var

cResult: string;

begin

cResult := AParams.Values['DialogResult'];

if Length(cResult) > 0 then begin

if cResult = '清除' then

IWMemo1.Clear

else

IWMemo1.Lines.Add(cResult);

end;

end;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);

begin

WebApplication.RegisterCallBack('AJAXConfirm', AJAXConfirm);

end;

procedure TIWForm1.btnConfirmAsyncClick(Sender: TObject;

EventParams: TStringList);

var

cDlgResult: string;

begin

WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(

StringReplace(jQConfirmExecuter.OnReady.Text, '@Message@',

'显示一个确认对话框就是如此简单,继续吗?', []));

end;

initialization

TIWForm1.SetAsMainForm;

end.