Jump to content

Mixing Javascript and SMS


Recommended Posts

I have been using ASM blocks in my project and find that I want to mix javascript and SMS. Below are two use cases.

  1. In an ASM block I would like to set a SMS attribute on a SMS object like a button doing something like TW3Button.Visible := True
  2. In an ASM blick I would like to call a SMS procedure or function to complete some common actions

Below is my psuedo code which I am hoping someone can correct and give some guidance on. I'm just looking for enough to be dangerous.....

EXAMPLE 1: Set attribute on button.

asm
	// Unsure how to do this here to call back to a button in SMS
	@W3Button1.Visible = True
end;

Example 2: Call SMS function from a javascript block

procedure TForm.DoSomething;
begin
	ShowMessage('Doing something');
end;

procedure TForm.OnButtonClick(Sender: TObject);
begin
	asm
		@DoSomething;
	end;
end;

For me this is the simplest I can make it which will help better understand the javascript-SMS links. I am hopeful that you understand, for these examples, it is not exactly how I'm using them, but for understanding I thouhgt this was the easiest examples I could do.

Thanks.

tim

Link to post
Share on other sites
  • Moderators

Example 2 : see below (first post in that thread) for some function call examples

 

Example 1 : depends on what attribute.

In your example you want to manipulate the visibility property of a button. These types of properties usually are mapped on a property or attribute of the underlying DOM-element. In this case you could use the style element visibility : W3Button1.handle.style.visibility := 'hidden' / 'visible'. 

'handle' is the doorway between object pascal on the left hand side and the dom on the right hand side. No need for an asm block here. 

you can go the other way  too :

  var x : variant := W3Button1.handle;
  asm
    console.log((@x).style.visibility);
  end;

but you can't directly manipulate the properties of an object pascal object, as in asm @W3Button1.Visible = true

Of course you can do some conditional js coding and execute object pascal code (like W3Button1.Visible := true;) depending on the return outcomes.

 

Out of habit I suppose I try to minimise the use of asm blocks (although there is nothing wrong with using them). 

The only times I have to use them if a js object doesn't have a create constructor but instead can only be instantiated by the 'new' keyword

  var formData : variant; 
  asm  @formData = new FormData();  end;
  //from here all methods and attributes of the js object are accessible outside an asm block     
  formData.append("userfile", EditBox1.handle.files[0]);

or wrapping a js function. (you can set @result in an asm block)

 

 

Link to post
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...