Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder 2 Preview » View Thread |
Messages 1 to 5 of 5 total |
Really simple TScript example request |
Mon, Jun 8 2015 11:53 AM | Permanent Link |
Trinione | I have spent the past hour scouring the forums and manual on how to use the TScript compononent and am no closer to understanding it.
Can a really simple step by step be posted here? I am sure it would help others get going with this as well. A JavaScript function --------------------------------------------------- function Sum(a, b) { return a+b; } --------------------------------------------------- And call this via ShowMessage(IntToStr(Sum(1,2)); |
Mon, Jun 8 2015 12:19 PM | Permanent Link |
Raul Team Elevate | On 6/8/2015 11:53 AM, Trinione wrote:
> Can a really simple step by step be posted here? I am sure it would help others get going with this as well. Quick-n-Dirty version : 1. save your function(s) into their own JS file (i called mine func.js and I have one function called MySum - same content as yours) 2. host it - i dropped it in the projects output folder so it gets servers by the IDE web server 3. tell EWB about it - mine is in the main form right after the Form class and before the form variable definition) external function MySum(a, b: Integer): Integer; 4. drop a TScript component 5. somewhere in your code load the script ( i did it in OnCreate) Script1.URL := 'func.js'; 6. then call your function(s) - i'm doing in on script load but you can obviously do it anywhere you want but make sure script onLoad succeedewd Raul //////////////////////////////////////////////////// // code unit main; interface uses WebCore, WebUI, WebForms, WebCtrls, WebComps; type TForm1 = class(TForm) Script1: TScript; procedure Form1Create(Sender: TObject); procedure Script1Load(Sender: TObject); private { Private declarations } public { Public declarations } end; external function MySum(a, b: Integer): Integer; var Form1: TForm1; implementation procedure TForm1.Form1Create(Sender: TObject); begin Script1.URL := 'func.js'; end; procedure TForm1.Script1Load(Sender: TObject); begin ShowMessage(IntToStr( MySum(5,6))); end; end. |
Mon, Jun 8 2015 12:48 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | << I have spent the past hour scouring the forums and manual on how to use the TScript compononent and am no closer to understanding it. >> You should only consider using this component if you need to link to JS code made available via a URL only, ala Google Maps. If you already have the JS source code file, then just include it as an external file in the project manager and skip using this component. EWB will emit the proper script links in the emitted HTML, and you won't have to worry about waiting until the code loads, etc. As for the external interface code necessary to use the JS code from EWB, see Raul's answer. Tim Young Elevate Software www.elevatesoft.com |
Mon, Jun 8 2015 12:49 PM | Permanent Link |
Raul Team Elevate | On 6/8/2015 12:19 PM, Raul wrote:
> On 6/8/2015 11:53 AM, Trinione wrote: >> Can a really simple step by step be posted here? I am sure it would >> help others get going with this as well. > > Quick-n-Dirty version : And just for completeness if you don't need to load the js from URL (for example you have a file with functions already) then just use the external files capability and EWB takes care of most of this for you. You do need to add the file in IDE so EWB knows to copy it to output folder as well as include with html. In case of external file you're skipping the TScript part so you just need to declare external function and then just use it. Raul |
Mon, Jun 8 2015 3:24 PM | Permanent Link |
Trinione | Thank you both.
I had read in another thread to put the 'external function..' in the interface section, and I had placed it before the 'uses ....' Also clear on the TScript now, and there is no need for it in this case. For those who are interested, here is the complete code. Remember to include the JavaScript file in the project via the External Files. sum.js ------------------- function Sum(a, b) { return a + b; } EWB Form ------------------------------------------------------- unit Unit1; interface uses WebCore, WebUI, WebForms, WebCtrls, WebBtns; external function Sum(a, b: Integer): Integer; type TForm1 = class(TForm) Button1: TButton; procedure Form1Create(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(Sum(1,2))); end; end. |
This web page was last updated on Thursday, March 28, 2024 at 08:36 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |