<div dir="ltr">This doesn't have any sense at all in Gambas.<br>What do you want to achieve?<br><div><br></div><div>I already wrote a small Gambas App (gui_server)<br><a href="https://gambas.one/gambasfarm/?id=821&action=search">https://gambas.one/gambasfarm/?id=821&action=search</a><br><a href="https://forum.crystal-lang.org/t/state-plans-of-gui-development-with-crystal/1615/28">https://forum.crystal-lang.org/t/state-plans-of-gui-development-with-crystal/1615/28</a><br></div><div>which allows to use many Gambas GUI objects from other scripting languages like Ruby, Python and Crystal(compiled Ruby like language).</div><div>Currently I walk the controls and classes with a for each loop to make all Objects and Properties available to GUI clients(TCP socket connection) by their Name. But I  am not happy with the performance of my code. I started with the Controls TextArea and Buttons, some events already work fine. </div><div><br></div><div>Example code in crystal language:</div><div>#connect to Gambas GUI via TCP<br>require "socket"<br>GUI_SERVER="localhost"<br>GUI_PORT=9090<br><br>class GuiClient<br>  property send_time = true<br>  @client = TCPSocket.new    #define var<br>  def connect<br>    @client = TCPSocket.new(GUI_SERVER,GUI_PORT)<br>  rescue err<br>    puts err.message  <br>    exit<br>  end<br><br>def send (object,value)<br>    puts "send(object,value)"     <br>    @client << object + "," + value + "\n"  #send to GUI_SERVER<br>    sleep 0.1    <br>end<br><br>def send (object)<br>  puts "send(object)"     <br>  @client << object + "\n"  #send to GUI_SERVER<br>  sleep 0.1<br>end<br><br>def disconnect<br>  @client.close<br>end  <br><br>def receive  #handle events<br>  <br>spawn do  <br>        loop do    <br>            event = @client.gets<br>            puts event<br>            case event <br>            when "Button1_clicked"  #stop button<br>              @send_time=false<br>            when "Button2_clicked"  #continue button<br>              @send_time=true<br>            when "Button3_clicked"  #clear textarea button<br>              send "textarea1.text",""    <br>            when "Button4_clicked"  #upcase textarea.text<br>              send "Textarea1.text" #request this value from gui elemen<br>              response = @client.gets<br>              puts "Response: ",response<br>              send "Textarea1.text",(response.not_nil! + "\n").upcase  #do upcase on string in textarea1<br>            when "Button5_clicked"  #upcase textarea.text<br>              send "Textarea1.text" #request this value from gui element<br>              response = @client.gets<br>              puts "Response: ",response<br>              send "Textarea1.text",(response.not_nil! + "\n").downcase  #do downcase on string in textarea1<br>            when "FMain_closed"     #Appilcation Window closed by user<br>            exit<br>            else  <br>            end  <br>        end<br>    end<br>  end<br>end  <br>#start the gambas gui server demo app<br>spawn do; system("~/src_gambas/gui_server/gui_server.gambas"); end<br>sleep 2   #give some time for startup<br>mygui = GuiClient.new<br>mygui.connect <br>mygui.receive<br>mygui.send "textlabel1.text","crystal + gambas = crybas"<br>mygui.send "button1.text","stop"<br>mygui.send "button2.text","continue"<br>#mygui.send "button3.enabled","0"  #disable a button<br>mygui.send "button3.text","clear texrarea"<br>mygui.send "button4.text","do Text.upcase"<br>mygui.send "button5.text","do Text.downcase"<br>#send key,value pairs for GUI Objects based on GTK or QT <br>mygui.send "FMain.Text","Crybas"   #set title of Application<br>mygui.send "Textarea1.Text","hello-textarea"<br><br>loop do   #Error writing to socket: Broken pipe when server closes<br>       mygui.send "Textbox1.Text",Time.local.to_s if mygui.send_time # display time in the gui<br>       sleep 1<br>    end   <br><br>sleep<br></div><div><br></div><div>Simple example:</div><div>I want to be able to query any Object like TextBox1.Text for the current String value. </div><div><br></div><div>BR,<br>Peter</div><div><br></div><div>Object introspection in Gambas code:</div><div><br></div><div>Public Sub full_instrospect(clsname As String)<br>   Dim cls As Class<br>   Dim count, pos As Integer<br>   Dim oo As Object<br>   Dim string$, result As String<br>   Dim propname, objname, clsn As String<br>   <br>   'lets see which class it could be   'textbox1.text<br>   Print "clsname: "; clsname<br>   pos = InStr(clsname, ".")<br>   If pos > 0 Then  <br>        clsn = Left$(clsname, pos - 1)                         ' button1.foreground\n<br>        propname = Trim$(Right$(clsname, Len(clsname) - pos))  ' foreground<br>        objname = clsn<br>        clsname = Left$(clsn, -1)     'remove number           ' button1      <br>        Else <br>        clsname = Trim$(clsname)  <br>        If IsNumber(Right$(clsname)) Then <br>        clsname = Left$(clsname, -1)  'remove number           ' button1<br>        Endif<br>      Endif  <br>        <br>   'cls = Class.load("Textarea")<br>   Try cls = Class.Load(clsname)<br>   If Error Then <br>     Print "full_instrospect() "; Error.Text<br>     Print #rsock, "full_instrospect() "; Error.Text<br>     Return<br>   Endif<br>   <br>   Print "Controls: "; Me.Controls.Count            'number of controls<br>   <br>   For Each oo In Me.Controls<br>        'Print "Current object: "; <a href="http://oo.name">oo.name</a><br>        If Not propname Then Print #rsock, " "; Trim$(<a href="http://oo.name">oo.name</a>)<br>        If UCase$(<a href="http://oo.name">oo.name</a>) = UCase$(clsname)<br>           Print "Found cls object: "; clsname<br>           Break<br>        Else If UCase$(<a href="http://oo.name">oo.name</a>) = UCase$(objname)<br>           Print "Found cls.object object: "; clsname; " "; objname<br>           Try result = Object.GetProperty(oo, propname)<br>           If Error Then<br>               Print #rsock, "full_instrospect() "; Error.Text<br>               Return<br>           Endif<br>           Print #rsock, result<br>           Return          ' found button1.foreground property<br>        Else       <br>           'Print "full_introspec(Object): "; clsname; " not matching"<br>        Endif      <br>  Next         <br><br>'oo = Me.Children[0]     'ref to instance of TextArea1, this app has just one control which is a Textarea<br>  Print oo                '(TextArea 0x559201bb78c8)<br>  Print oo.Name; ":"      'TextArea1<br>  Textarea1_object = oo   'set object ref in a global var<br>  <br>  count = 0<br>  For Each string$ In cls.Symbols      'iterate over all symbols<br>     Print string$; ",";<br>     Print #rsock, string$; ",";<br>     count += 1<br>  Next<br>  Print "\nSymbols found: "; count; "\n"<br>  Print #rsock, "\nSymbols found: "; count; "\n"<br>  count = 0<br> <br> For Each string$ In cls.Symbols<br>         Print "\nTRY: "; count; " ";<br>         If Not objname Then Print #rsock, "\nTRY: "; clsname; " "; count; " ";<br>         Try result = Object.GetProperty(oo, string$)<br>             If result Not Begins ":" 'is an event !<br>                    Print "Symbol: "; string$; " Value: "; result; "";<br>                    If Not objname Then Print #rsock, "Symbol: "; string$; " Value: "; result; "";<br>                    Endif<br>         If Error Then<br>           Print " Error: "; Error.code; " "; Error.Text; " ";<br>           Print #rsock, " Error: "; Error.code; " "; Error.Text; " ";<br>         Endif<br>         count += 1<br>     Next<br>     Print #rsock, "\n"<br> End<br></div><div><br></div><div><br></div></div>