Hi,
In my test project, I have a function in AfterScript in UniHtmlFrame.
I can call a Function and define a variable with UniFormAjaxEvent. There is no problem until this point.
But when I click on a button I want to get the Result value returned from the function to Result.Text box. "Result.Text := js(Param.Text);".
When Unisession.AddJS runs, I assign ReturnValue in AjaxEvent. But when the function is finished, AjaxEvent assigns it.
Thus, it returns the value as the previous value.
Sample test project is attached.
Thank you.
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniButton, uniGUIBaseClasses,
uniEdit, uniPanel, uniHTMLFrame, uniLabel;
type
TMainForm = class(TUniForm)
result: TUniEdit;
UniButton1: TUniButton;
UniHTMLFrame1: TUniHTMLFrame;
param: TUniEdit;
UniLabel1: TUniLabel;
UniLabel2: TUniLabel;
procedure UniButton1Click(Sender: TObject);
procedure UniFormAjaxEvent(Sender: TComponent; EventName: string;
Params: TUniStrings);
private
ReturnValue : string;
function js(test: string): string;
public
{ Public declarations }
end;
function MainForm: TMainForm;
implementation
{$R *.dfm}
uses
uniGUIVars, MainModule, uniGUIApplication;
function MainForm: TMainForm;
begin
Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;
function TMainForm.js(test: string): string;
begin
UniSession.AddJS('myFunction('+ test +')');
Result := ReturnValue;
end;
procedure TMainForm.UniButton1Click(Sender: TObject);
begin
result.Text := js(param.Text);
end;
procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
Params: TUniStrings);
begin
if EventName = '_test' then
begin
ReturnValue := Params.Values['Value'];
end;
end;
initialization
RegisterAppFormClass(TMainForm);
end.
Test.rar