Need a brief description of the 'Runtime' library v5.20b1

Just starting out? Need help? Post your questions and find answers here.
User avatar
Demivec
Addict
Addict
Posts: 4258
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Need a brief description of the 'Runtime' library v5.20b1

Post by Demivec »

I looked at the example code demonstrating the use of the 'Runtime' library but didn't catch the vision of it. It would help to have a brief description of what the library's purpose is and the items included in the library itself.


Specifically, what are each of these for and how are they used:
  • 'Runtime' keyword
    GetRuntimeInteger(quoted_string_literal)
    IsRuntime(quoted_string_literal)
Are there additional functions besides these?
User avatar
Demivec
Addict
Addict
Posts: 4258
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Demivec »

I've discovered a list of some (maybe all) of the functions in the 'Runtime' library that were posted in the German PureBasic forum:

GetRuntimeDouble (Name) - Return the Runtime double item value.
GetRuntimeInteger (Name) - Return the Runtime integer item value.
GetRuntimeString (Name) - Return the Runtime string item value.
IsRuntime (Name) - Check If the specified item is available at Runtime.
SetRuntimeDouble (Name, Value) - Change the Runtime item value.
SetRuntimeInteger (Name, Value) - Change the Runtime item value.
SetRuntimeString (Name, String$) - Change the Runtime item string.


I still could use some help on the library's purpose or general use. It would appear the 'Runtime' keyword is used to declare a scope or classification. It just doesn't appear how that may be of any use. Please enlighten me. :)
Little John
Addict
Addict
Posts: 4775
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Little John »

Demivec wrote:Need a brief description of the 'Runtime' library v5.20b1
Me too. :-)
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Bisonte »

And not only for the Runtime library :!:
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Deluxe0321 »

So far Runtime seems to be needed if you create a dialog via XML-Input.
Just remove the "Runtime" @ StringBoomBox() or CheckBoxEvent() and check the debug output.

Code: Select all

Runtime Procedure StringBoomBox()
  GadgetID.i = DialogGadget(0,"text_gadget") 
  If GadgetID.i > -1
    SetGadgetText(GadgetID.i,"I'm called from a runtime :)")
  EndIf
EndProcedure

Runtime Procedure CheckBoxEvent()
  
  GadgetID.i = DialogGadget(0,"string_gadget") 
  If GadgetID.i > -1
    SetGadgetText(GadgetID.i,"Activated from "+Str(EventGadget())+" | "+Str(GadgetID.i))
  EndIf
  Debug "CheckBoxEvent"
EndProcedure

Procedure Main()

  ;sorry for this mess, needed to include the xml ;)
  Protected XMLS.s = "<?xml version="+#DQUOTE$+"1.0"+#DQUOTE$+"?>"+#CRLF$+#CRLF$+
  "<!-- Window -->"+#CRLF$+
  "<window id="+#DQUOTE$+"0"+#DQUOTE$+" name="+#DQUOTE$+"hello"+#DQUOTE$+" text="+#DQUOTE$+"Window"+#DQUOTE$+" label="+#DQUOTE$+"TestDialog"+#DQUOTE$+" width="+#DQUOTE$+"320"+#DQUOTE$+" height="+#DQUOTE$+"10"+#DQUOTE$+" flags="+#DQUOTE$+"#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget"+#DQUOTE$+">"+#CRLF$+
  "   <splitter width="+#DQUOTE$+"300"+#DQUOTE$+" height="+#DQUOTE$+"500"+#DQUOTE$+">"+#CRLF$+
  "     <hbox>"+#CRLF$+
  "      <checkbox name="+#DQUOTE$+"checkbox1"+#DQUOTE$+" text="+#DQUOTE$+"Run only one Instance"+#DQUOTE$+" disabled="+#DQUOTE$+"yes"+#DQUOTE$+" Flags="+#DQUOTE$+""+#DQUOTE$+"/>"+#CRLF$+
  "      <progressbar text="+#DQUOTE$+"Vrey vreyv rye"+#DQUOTE$+"/>"+#CRLF$+
  "      <trackbar text="+#DQUOTE$+"Ole"+#DQUOTE$+" invisible="+#DQUOTE$+"no"+#DQUOTE$+" flags="+#DQUOTE$+"#PB_TrackBar_Ticks|#PB_TrackBar_Ticks|#PB_TrackBar_Ticks"+#DQUOTE$+" width="+#DQUOTE$+"150"+#DQUOTE$+"/>"+#CRLF$+
  "      <option text="+#DQUOTE$+"option 1"+#DQUOTE$+" name="+#DQUOTE$+"option1"+#DQUOTE$+" onevent="+#DQUOTE$+"CheckBoxEvent()"+#DQUOTE$+"/>"+#CRLF$+
  "      <option text="+#DQUOTE$+"option 2"+#DQUOTE$+"/>"+#CRLF$+
  "     </hbox>"+#CRLF$+
  "     <vbox>"+#CRLF$+
  "      <listview text="+#DQUOTE$+"option 3"+#DQUOTE$+" height="+#DQUOTE$+"50"+#DQUOTE$+"/>"+#CRLF$+
  "      <button text="+#DQUOTE$+"Click me"+#DQUOTE$+" name="+#DQUOTE$+"string"+#DQUOTE$+" onevent="+#DQUOTE$+"StringBoomBox()"+#DQUOTE$+"/>"+#CRLF$+
  "      <listicon text="+#DQUOTE$+"option 4"+#DQUOTE$+" height="+#DQUOTE$+"50"+#DQUOTE$+"/>"+#CRLF$+
  "      <string name="+#DQUOTE$+"string_gadget"+#DQUOTE$+" text="+#DQUOTE$+"string content"+#DQUOTE$+"/>"+#CRLF$+
  "      <editor text="+#DQUOTE$+"editorgadget"+#DQUOTE$+" height="+#DQUOTE$+"50"+#DQUOTE$+"/>"+#CRLF$+
  "      <text text="+#DQUOTE$+"Text gadget"+#DQUOTE$+" name="+#DQUOTE$+"text_gadget"+#DQUOTE$+"/>"+#CRLF$+
  "     </vbox> "+#CRLF$+   
  "   </splitter>"+#CRLF$+
  "</window>"
 
  Debug "Opening dialog.."
  Debug "Data: "+XMLS.s
 
  If CatchXML(0, @XMLS.s,StringByteLength(XMLS.s))
    
    ;IsRuntime(Var.s) usage
    If Not IsRuntime("StringBoomBox()") : Debug "StringBoomBox() --> not runtime, you will see an error.." : EndIf
    If Not IsRuntime("CheckBoxEvent()") : Debug "CheckBoxEvent() --> not runtime, you will see an error.." : EndIf
    
    If CreateDialog(0)
 
        If Not OpenXMLDialog(0, 0, "hello")
          Debug DialogError(0)
          End ;- I get an IMA here, can someone confirm?
        EndIf
         
        HideWindow(0, 0)
   
        While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
      EndIf
    Else
   
      Debug "nope.."
 
    EndIf
EndProcedure

Main()
//edit: added some dialog stuff
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Fred »

'Runtime' add information in the executable to access these token at runtime. For example, you can add a procedure as runtime, and then get its address by using a string. It's useful for module or libraries so you can query the executable about some of its component (it's a bit like RTTI in C++). The new Dialog lib use it to get the procedure for event, directly from the XML. It wouldn't be possible without that. So you can see it like a standard way to access internal data. You can also imagine a small scripting frontend which could change the value of your variables on the run.
User avatar
Demivec
Addict
Addict
Posts: 4258
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Demivec »

Fred wrote:You can also imagine a small scripting frontend which could change the value of your variables on the run.
Thank you for your explanation.

To restate what you said and verify that I am understanding correctly, it essentially allows referring to variables, procedures, and constants by a string containing their name. This information previously (and normally) wasn't saved as part of the compilation for access at runtime. This opens the possibility to use dynamic programming that is created at runtime to access the variables, procedures, and constants designated with the 'Runtime' keyword.

Here is a simple sample code:

Code: Select all

Define d1tmp = 1, d2tmp = 4, d3tmp = 9

Runtime d1tmp, d2tmp, d3tmp ;what is the scope of these?

Define i
For i = 0 To 2
  Debug GetRuntimeInteger("d" + Random(3, 1) + "tmp")
Next

Procedure test()
  Protected x$, i
  Debug "test_1()"
  For i = 0 To 10
    x$ = "d" + Random(3, 1) + "tmp"
    Debug x$ + " = " + GetRuntimeInteger(x$) ;Are runtime variables always accessible, even when they are normally out of scope?
  Next
EndProcedure

test()
To summarize the Dialog library, it allows the creation and accessing of objects such as windows and gadgets, via string descriptions using XML, at runtime.

@Deluxe0321: thanks for your example code. It doesn't run perfectly but does expand my views a bit. How do you know what is needed in the XML to set up each of the gadgets and such?


Neither the 'Runtime' nor the 'Dialog' library allow creation of variables, procedures, or constants at runtime.


@Edit: made a small change to the code ... thanks fsw.
Last edited by Demivec on Fri Jun 21, 2013 9:33 pm, edited 2 times in total.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Need a brief description of the 'Runtime' library v5.20b

Post by fsw »

Why do you need this?

Code: Select all

Dim var.s(2)
var(0) = "d1tmp"
var(1) = "d2tmp"
var(2) = "d3tmp"
It's never accessed...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Demivec
Addict
Addict
Posts: 4258
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Demivec »

fsw wrote:Why do you need this?

Code: Select all

Dim var.s(2)
var(0) = "d1tmp"
var(1) = "d2tmp"
var(2) = "d3tmp"
It's never accessed...
This is actually an artifact that I neglected to remove as I modified the code while posting the message. It has been corrected. Thanks for pointing it out.
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: Need a brief description of the 'Runtime' library v5.20b

Post by Deluxe0321 »

Demivec wrote:@Deluxe0321: thanks for your example code. It doesn't run perfectly but does expand my views a bit. How do you know what is needed in the XML to set up each of the gadgets and such?
I used the example (http://www.purebasic.fr/english/viewtop ... 14#p415214) provided by Fred and messed around with it. It's kinda self explanatory.
Post Reply