agraham Expert Licensed User Longtime User Feb 19, 2009 #21 can i addevent from all basic script objects to one sub Click to expand... I don't see why not if that's what you need to do but I wouldn't recommend it. If that event code manipulates GUI elements or calls DoEvents there might be a risk of re-entry. Even then it might be OK as long as your event code is threadsafe. all scripts run in threads.what happend,if 2 or more scripts fired CallHost at ONE moment? Click to expand... I think all the code involved is threadsafe so it should work as you would expect. CallHost runs on the script thread and behaves just like thread events in the Threading library. It posts a message to the main window thread message loop to run the event code in Basic4ppc on the main thread and waits until the event code finishes then returns. Normally an event cannot interrupt another event, although if you do DoEvents or manipulate GUI elements in your event code that might not be a good idea as that might run the main window message loop and let a second event re-enter your event code before the first has finished. and when event fired,it performed in thread or main thread? Click to expand... All Basic4ppc events run on the main thread so they are allowed to manipulate GUI elements without risk.
can i addevent from all basic script objects to one sub Click to expand... I don't see why not if that's what you need to do but I wouldn't recommend it. If that event code manipulates GUI elements or calls DoEvents there might be a risk of re-entry. Even then it might be OK as long as your event code is threadsafe. all scripts run in threads.what happend,if 2 or more scripts fired CallHost at ONE moment? Click to expand... I think all the code involved is threadsafe so it should work as you would expect. CallHost runs on the script thread and behaves just like thread events in the Threading library. It posts a message to the main window thread message loop to run the event code in Basic4ppc on the main thread and waits until the event code finishes then returns. Normally an event cannot interrupt another event, although if you do DoEvents or manipulate GUI elements in your event code that might not be a good idea as that might run the main window message loop and let a second event re-enter your event code before the first has finished. and when event fired,it performed in thread or main thread? Click to expand... All Basic4ppc events run on the main thread so they are allowed to manipulate GUI elements without risk.
B Byak@ Active Member Licensed User Feb 19, 2009 #22 big thanks Agraham...it is not good. and nevertheless maybe you right simple sample with 2(or more) scripts at one time?please =)
big thanks Agraham...it is not good. and nevertheless maybe you right simple sample with 2(or more) scripts at one time?please =)
agraham Expert Licensed User Longtime User Feb 19, 2009 #23 Byak@ said: it is not good. Click to expand... What sort of problem are you having?
agraham Expert Licensed User Longtime User Feb 19, 2009 #24 Look at this example of three Basic threads going at once. Attachments MultiBasic.sbp MultiBasic.sbp 1.8 KB · Views: 20
B Byak@ Active Member Licensed User Feb 19, 2009 #25 2Agraham I try to creates plugins for my program.every plagin must create panel and add webbrowser to it.and every x seconds every plugin add some info to his webbrowser. thanks for sample=)
2Agraham I try to creates plugins for my program.every plagin must create panel and add webbrowser to it.and every x seconds every plugin add some info to his webbrowser. thanks for sample=)
agraham Expert Licensed User Longtime User Feb 20, 2009 #26 I think that I have found a threading bug in Basic4ppc so if you are running two or more threads and think you are losing events then you probably are! I'll discuss this with Erel.
I think that I have found a threading bug in Basic4ppc so if you are running two or more threads and think you are losing events then you probably are! I'll discuss this with Erel.
Erel B4X founder Staff member Licensed User Longtime User Feb 20, 2009 #27 I read your mail and will add it to the next version todo list.
agraham Expert Licensed User Longtime User Feb 26, 2009 #28 Version 3.1 posted which has a new Keyword, CallHostSub, that can be used both as a statement and a function. This is available only to scripts running in optimised compiled applications. In a legacy environment the script will error and halt. CallHostSub allows a B4Script to directly execute Basic4ppc host program Subs and, as the Sub executes directly rather than going via an event, it has much, much higher performance than CallHost. It provides a much easier and more direct way of allowing a script access to host program functionality, particularly for anyone writing a plug-in. The downside is that, like a Thread Sub, a Sub called by CallHostSub must not touch GUI elements if it is not running on the main thread. For this you must use CallHost, Print or Msgbox events. Note that BasicLib.New1 now requires "B4PObject(1)" as a parameter. Last edited: May 1, 2009
Version 3.1 posted which has a new Keyword, CallHostSub, that can be used both as a statement and a function. This is available only to scripts running in optimised compiled applications. In a legacy environment the script will error and halt. CallHostSub allows a B4Script to directly execute Basic4ppc host program Subs and, as the Sub executes directly rather than going via an event, it has much, much higher performance than CallHost. It provides a much easier and more direct way of allowing a script access to host program functionality, particularly for anyone writing a plug-in. The downside is that, like a Thread Sub, a Sub called by CallHostSub must not touch GUI elements if it is not running on the main thread. For this you must use CallHost, Print or Msgbox events. Note that BasicLib.New1 now requires "B4PObject(1)" as a parameter.
B Byak@ Active Member Licensed User Feb 27, 2009 #29 big thanks agraham!it's very well! i have problem...can i get variable from main code to script when it doing not in start!for example i'm use callhost for do some operations in main cose.and can i get result to script? mya be it ias real with GetGlobal or GetLocal?
big thanks agraham!it's very well! i have problem...can i get variable from main code to script when it doing not in start!for example i'm use callhost for do some operations in main cose.and can i get result to script? mya be it ias real with GetGlobal or GetLocal?
agraham Expert Licensed User Longtime User Feb 27, 2009 #30 As you say, use the GetXXX and SetXXX methods to transfer data to and from the script. In this plugin demo http://www.b4x.com/forum/share-your-creations/3705-creating-plugins-demonstration.html it is done a lot.
As you say, use the GetXXX and SetXXX methods to transfer data to and from the script. In this plugin demo http://www.b4x.com/forum/share-your-creations/3705-creating-plugins-demonstration.html it is done a lot.
agraham Expert Licensed User Longtime User Mar 2, 2009 #31 Version 3.2 posted which has a new Keyword, CallHostGuiSub, that can be used both as a statement and a function and allows scripts to safely call Subs that manipulate GUI elements. This is available only to scripts running in optimised compiled applications. I should have thought to include this in v3.1 as it makes CallHost obsolete for optimised compiled apps and lets scripts easily manipulate GUI elements. Plugins should be easier as now you just put all the Subs that interface to your plugin in a module, document them, and let your user scripts call them. As scripts might be interested in color I have included RGB, GetR, GetG and GetB functions and all the Basic4ppc colour constants. A notable oversight of mine was not to include CallSub, it is now implemented. Step and break now stop before the line is executed rather than after. This is to match the behaviour of the IDE and my forthcoming debugger for optimised compiled apps which will require the next version of Basic4ppc.
Version 3.2 posted which has a new Keyword, CallHostGuiSub, that can be used both as a statement and a function and allows scripts to safely call Subs that manipulate GUI elements. This is available only to scripts running in optimised compiled applications. I should have thought to include this in v3.1 as it makes CallHost obsolete for optimised compiled apps and lets scripts easily manipulate GUI elements. Plugins should be easier as now you just put all the Subs that interface to your plugin in a module, document them, and let your user scripts call them. As scripts might be interested in color I have included RGB, GetR, GetG and GetB functions and all the Basic4ppc colour constants. A notable oversight of mine was not to include CallSub, it is now implemented. Step and break now stop before the line is executed rather than after. This is to match the behaviour of the IDE and my forthcoming debugger for optimised compiled apps which will require the next version of Basic4ppc.
B Byak@ Active Member Licensed User Mar 3, 2009 #33 :-[ may be sample for new function?and i not fint her in manual...
agraham Expert Licensed User Longtime User Mar 3, 2009 #34 Byak@ said: :-[ may be sample for new function?and i not fint her in manual... Click to expand... Which function, and what's missing from the help?
Byak@ said: :-[ may be sample for new function?and i not fint her in manual... Click to expand... Which function, and what's missing from the help?
B Byak@ Active Member Licensed User Mar 3, 2009 #35 CallHostGuiSub! i don't found it in manual and don't found script with it
agraham Expert Licensed User Longtime User Mar 3, 2009 #36 CallHostGuiSub is in B4Script help->Keywords->General between the topics CallHostSub and CallSub, a bit out of alphabetical order I'm afraid. It is described in BasicLib help in Overview at the ninth paragraph of "Limitations and differences". I didn't bother with a demo as it is so simple. To check it works edit "CallHostSub" to "CallHostGuiSub" in CallHostSub.src.
CallHostGuiSub is in B4Script help->Keywords->General between the topics CallHostSub and CallSub, a bit out of alphabetical order I'm afraid. It is described in BasicLib help in Overview at the ninth paragraph of "Limitations and differences". I didn't bother with a demo as it is so simple. To check it works edit "CallHostSub" to "CallHostGuiSub" in CallHostSub.src.
B Byak@ Active Member Licensed User May 1, 2009 #37 Hello Agraham! i have problem when use Scripting lib in thread. when i'm use "callhostguisub" i want see sender (Scripting object) but... Please see my sample. I think this is because i'm use Formex... :sign0085: p.s. and i'm found bug- rnd(min,max) doesn't work Attachments getREALsender.sbp getREALsender.sbp 1.9 KB · Views: 13 Last edited: May 1, 2009
Hello Agraham! i have problem when use Scripting lib in thread. when i'm use "callhostguisub" i want see sender (Scripting object) but... Please see my sample. I think this is because i'm use Formex... :sign0085: p.s. and i'm found bug- rnd(min,max) doesn't work
agraham Expert Licensed User Longtime User May 1, 2009 #38 Byak@ said: i want see sender (Scripting object) Click to expand... Read the third paragraph of the Threading topic of the FormExDesktop help and see the FormExDesktop.Sender property. Sorry about Rnd()! I missed a line of code out that effectively disables it. I'll fix it soon.
Byak@ said: i want see sender (Scripting object) Click to expand... Read the third paragraph of the Threading topic of the FormExDesktop help and see the FormExDesktop.Sender property. Sorry about Rnd()! I missed a line of code out that effectively disables it. I'll fix it soon.
B Byak@ Active Member Licensed User May 1, 2009 #39 Agraham, for events Message,Ended and any i'm use EnableThreadEvent and formex.sender return real sender...BUT how can i'm use this with callhostgui ?it is not event! and if i do Code: Copy Sub test Msgbox(formex.sender) i=StrReplace(Sender,"script","") 'why sender is not a 'script'??? i=1 AddObject("formex"&i,"Formex") Control("formex"&i,"Formex").new2("formm"&i,i,200,200) Control("formex"&i,"Formex").showmodal End Sub msgbox(formex.sender) return ERROR "Object reference not set to instance of an object"
Agraham, for events Message,Ended and any i'm use EnableThreadEvent and formex.sender return real sender...BUT how can i'm use this with callhostgui ?it is not event! and if i do Code: Copy Sub test Msgbox(formex.sender) i=StrReplace(Sender,"script","") 'why sender is not a 'script'??? i=1 AddObject("formex"&i,"Formex") Control("formex"&i,"Formex").new2("formm"&i,i,200,200) Control("formex"&i,"Formex").showmodal End Sub msgbox(formex.sender) return ERROR "Object reference not set to instance of an object"
agraham Expert Licensed User Longtime User May 1, 2009 #40 As you haven't posted your script I have no idea what your script is trying to do. CallHostGuiSub has nothing to do with Sender because, like you said, it does not cause an event. You will have to pass a script identifier to the Sub you are calling and you can pass that identifier to a script in its args() when it starts. Remember you only need to use CallHostGuiSub if you want to access GUI elements, otherwise CallHostSub is a LOT faster but may raise threading issues as it runs on the calling thread and not the GUI thread.
As you haven't posted your script I have no idea what your script is trying to do. CallHostGuiSub has nothing to do with Sender because, like you said, it does not cause an event. You will have to pass a script identifier to the Sub you are calling and you can pass that identifier to a script in its args() when it starts. Remember you only need to use CallHostGuiSub if you want to access GUI elements, otherwise CallHostSub is a LOT faster but may raise threading issues as it runs on the calling thread and not the GUI thread.