Jump to content

how to call a javascript function implemented in a file loaded in servermodule custom files??


SIRE Software

Recommended Posts

Good afternoon!

In my application i have a button that in the click event does some stuff but at the end of the event i need to call a javascript function and pass it a string as a parameter, the function will be implemented in a file that i will load in the ServerModule's custom files property?

how could i do that??

 

thanks in advance!

Link to comment
Share on other sites

4 hours ago, Victor Dominguez said:

Good afternoon!

In my application i have a button that in the click event does some stuff but at the end of the event i need to call a javascript function and pass it a string as a parameter, the function will be implemented in a file that i will load in the ServerModule's custom files property?

how could i do that??

 

thanks in advance!

 

Hi,

I use this to start every javascript commands from file or direct command execute:

 

procedure JAVASCRIPT_EXEC (Sender: TObject; fType, Data, DataObjectsList  : AnsiString);
var
I           : Integer;
DataList    : TStringList;
sObject     : TObject;
begin

if (Sender <> nil) then begin
  TRY
    With TUniControl (Sender) do begin
      ScreenMask.Message := 'Please, wait ...';
      ScreenMask.WaitData := False;//True;
      ScreenMask.Enabled := False;//True;
    end;
  EXCEPT

  END;
end;

IF (Length (Data) > 1) then begin
    DataList := TStringList.Create;
    DataList.StrictDelimiter := True;
    DataList.Delimiter := ';';

    //read data from file if file exists
   If FileExists (Data) then  begin

     DataList.LoadFromFile (Data);

     Data := TRIM (DataList.Text);
     DataList.Clear;
     //DataList.Free;
     //If Assigned(DataList) then
     //   FreeandNil (DataList);
   end;

end;

//TUnibutton (Sender).ClientEvents.ExtEvents.Values ['click'] := 'function click(sender, e, eOpts){' + Data + '}';

//UniSession.JSCode (Data);
UniSession.AddJs (Data);
//UniSession.JSONDirect (Data);
end;
 

This function I can start from every component

  • Like 1
Link to comment
Share on other sites

Other solution for Your needs:

//load custom file javascript function

if (FileExists (ExtractFilepath (Application.ExeName) + '\files\voicescript.js')) then
    CustomFiles.Add ('files/voicescript.js');
 

//use function

unisession.AddJS('youfunctionname (functionparameters)' );
 

  • Like 1
Link to comment
Share on other sites

9 hours ago, irigsoft said:

Other solution for Your needs:

//load custom file javascript function

if (FileExists (ExtractFilepath (Application.ExeName) + '\files\voicescript.js')) then
    CustomFiles.Add ('files/voicescript.js');
 

//use function

unisession.AddJS('youfunctionname (functionparameters)' );
 

Thank you so much!

This is so helpful.

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...