SEGNA Posted March 1, 2023 Share Posted March 1, 2023 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 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 1, 2023 Share Posted March 1, 2023 58 minutes ago, SEGNA said: 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; Hello, This approach won't work... I will try to provide an example. Quote Link to comment Share on other sites More sharing options...
SEGNA Posted March 1, 2023 Author Share Posted March 1, 2023 Hello, Thank you for your answer. Waiting for your sample. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 1, 2023 Share Posted March 1, 2023 26 minutes ago, SEGNA said: Thank you for your answer. Waiting for your sample. Although, sorry, it probably won't work that way. Once again, specify what all this is for? Quote Link to comment Share on other sites More sharing options...
Ron Posted March 3, 2023 Share Posted March 3, 2023 procedure TMainForm.UniButton1Click(Sender: TObject); begin UniSession.AddJS('function doTest(){ajaxRequest(MainForm.form, ["test"], { data: 58 });};doTest();'); end; procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'test' then ShowMessage(Params.Values['data']); end; 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.