Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

How to execute a block of code in a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to execute a block of code in a variable

    I have a UI_POPUP_MENU() that compiles and returns code to be run. Stored in a variable.
    A typical example of the contents of the variable, a string of code, can be recreated with the following example in IW
    Code:
    codeseg=<<%str%
    if ui_get_password("SECURITY PASSWORD","Supervisor number")="Mike"
        this.delete()
    end if
    %str%
    I imagined I could use EVALUATE_TEMPLATE(codeseg) but it doesn't appear to execute.
    Executing the individual lines one at a time in IW does what it should, as expected.
    I then tried one line at a time as follows
    Code:
    dim shared foo as c
    for each foo in codeseg
        EVALUATE_TEMPLATE(foo)
    next
    Can anyone see any reason why that doesn't work either or is there another function?

  • #2
    Re: How to execute a block of code in a variable

    I put in a msgbox before 'this.delete' and it pops up. I ran the code in a new script window an hit run.

    Code:
    codeseg=<<%str%
    if ui_get_password("SECURITY PASSWORD","Supervisor number")="Mike"
    	msgbox("aaa")
        this.delete()
    end if
    %str%
    
    evaluate_template(codeseg)
    What is the context of the code when it runs. i would be suspicious of the what 'this' is referrring to at run time.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


    • #3
      Re: How to execute a block of code in a variable

      Not clear on what you are trying to accomplish with this.delete().

      If you are trying to delete a table record you have to have a table pointer and set the change mode.

      dim tbl as P
      tbl = table.current()
      tbl.change_begin()
      tbl.delete()
      tbl.change_end(.T.)

      If this refers to the current object it would seem you're trying to delete the menu itself or the visible form?
      There can be only one.

      Comment


      • #4
        Re: How to execute a block of code in a variable

        Just added a msgbox after 'this.delete' as well. The one before pops up but the one after does not indicating that there is a problem with 'this.delete'.

        Code:
        codeseg=<<%str%
        if ui_get_password("SECURITY PASSWORD","Supervisor number")="Mike"
            msgbox("aaa")
            this.delete()
            msgbox("bbb")
        end if
        %str%
        EDIT: What Stan said.
        Tim Kiebert
        Eagle Creek Citrus
        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

        Comment


        • #5
          Re: How to execute a block of code in a variable

          Thanks for the quick responses.
          On an embedded browse, an event pops up a menu for user to select from. The event in this case a doubleclick in a cell. to act on context contained in that cell
          The menu will always know "this" as the object that it was called from -maybe a bad example that particular selection with "this". None of the code runs, it should display the password dlg anyway.
          Here is the menu code you can run it from IW
          Code:
          mfmt=<<%str%
          {I=$$generic.recorder}{DATA=!'BRWS=this.browse1{r{ndim shared brws as p{r{nbrws = Browse1.this{r{nfldname = brws.active_drilldown(){r{nshortfldname = word(fldname, 4, ":"){r{nfldval = eval(fldname + ".text"){r{n'ui_msg_box(fldval,fldname+" Shortname "+shortfldname ){r{nAddeventDlg(BROWSE1:ord_id.text,shortfldname ){r{nend{r{n'debug(1){r{ndim shared brws as p{r{nbrws = ship_schedule:browse1.this{r{nfldname = Brws.active_drilldown(){r{nshortfldname = word(fldname, 4, ":"){r{nAddeventDlg(brws.ord_id,shortfldname )}Add Event Record G
          {I=$$code.class}{DATA=!brp=parentform.browse1{r{nbrr=brp.Current_Record(){r{nif is_object("Orderheader")=.f.{r{n{t{tfrm=form.load("Orderheader"){r{nend if{r{nfrm = obj("orderheader"){r{nftb=frm.Table_Get(){r{nftb.fetch_goto(brr){r{nfrm.Resynch(){r{nfrm.Activate(){r{n}{PROMPT=View this record on the ODR}Switch to ODR
          {I=$a5_record_change}{DATA=!topparent.GetActiveObjParent().allow_change(.t.)}{ENABLE=(.not.allow_editing())}Edit (Alt+C){tab}Alt+C
          -
          {I=$a5_delete}{DATA=!if ui_get_password("SECURITY PASSWORD","Supervisor number")="Mik"{r{nthis.delete(){r{nend if}&Delete
          {DATA=!this.select(1,1000000)}Select &All
          %str%
          code2run=ui_popup_menu(mfmt)
          The code to run is text content of var->code2run based on your selection from the menu.
          I just want to run whatever code is returned.

          Comment


          • #6
            Re: How to execute a block of code in a variable

            Cause of the problem, circumstances are...
            It works currently correctly on a right click menu. Perfectly.
            The MAJOR problem users have is that they can right click believing that where the mouse pointer is is the cell that is active and collect data for the wrong subject, if they did not first consciously first click on the cell they are pointing at. What a mess that has been creating.

            Double click will force the correct cell to activate first.
            I will in any event disable or remove that delete - it is not an important function here. I can deal with that elsewhere.
            As mentioned it was an unfortunate selection of a random option, - , none of them can I get to run.
            Last edited by Ray in Capetown; 11-09-2014, 06:21 PM.

            Comment


            • #7
              Re: How to execute a block of code in a variable

              BTW Stan that code run just as it is will delete the browse record given the correct password. Thats not the problem tho'
              Last edited by Ray in Capetown; 11-09-2014, 07:07 PM.

              Comment


              • #8
                Re: How to execute a block of code in a variable

                I haven't used the syntax for the popup menu for a while so not sure how it gets there but in the definition just after the 'DATA=' there is an exclamation "!". This is being returned with the result and is the first character in the resulting code that you subsequently try to run with evaluate_template causing a syntax error. Either remove it from the menu definition or strip it out before feeding the string to evaluate_template function.
                Tim Kiebert
                Eagle Creek Citrus
                A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                Comment


                • #9
                  Re: How to execute a block of code in a variable

                  More or less Tim
                  I guess there is no generally known function to execute a codeblock as is.
                  I can strip the !+space out, convert all -"- to -\"-, separate the lines for each... but some of the code line structures dont work with evaluate_template.
                  For the short term to resolve the issue, I will write all the code options into a script and use GOTO to run the relevant one.

                  Comment


                  • #10
                    Re: How to execute a block of code in a variable

                    Originally posted by Ray in Capetown View Post
                    BTW Stan that code run just as it is will delete the browse record given the correct password. Thats not the problem tho'
                    Well it may.

                    The xbasic explorer indicates the method .delete_record() and doesn't show .delete(). The docs say
                    The <OBJECT>.DELETE() method deletes the named object from disk.

                    Whatever works.
                    There can be only one.

                    Comment


                    • #11
                      Re: How to execute a block of code in a variable

                      Thanks Stan. I didn't know that. Actually I modified a standard browse right click menu, retained the delete adding password protection and some new options

                      I have a solution to not being able to run a number of lines of code in memory, a little less snappy but here below for anyone interested
                      1. Simplified the menu eliminating executable code
                      2. the doubleclick event runs a standard saved script that displays the menu returning the user selection
                      3. a series of select case statements and goto's selects the relevant code
                      Last edited by Ray in Capetown; 11-10-2014, 11:09 AM.

                      Comment


                      • #12
                        Re: How to execute a block of code in a variable

                        Correction Stan I checked on what you said.
                        I had removed that delete option a day or so ago from the production system
                        recovered back to earlier vers to try it. It does nothing after entering the password.
                        You are right.

                        Comment


                        • #13
                          Re: How to execute a block of code in a variable

                          Originally posted by Ray in Capetown View Post
                          I guess there is no generally known function to execute a codeblock as is.
                          I do not know if this helps you anyway but I wanted one time run xbasic function from couchdb (saved in character field in couchdb)

                          You get the idea from this code:

                          Code:
                          ...
                          dim resp as p
                          resp = http_fetch(req)
                          dim parsed as p = json_parse(resp.body)
                          dim test as C = stritran(parsed.aihe,"#",crlf())
                          dim pftest as P = compile_template(test)
                          
                          ?pftest.Hoi("Ken")
                          = "Hello, Ken"
                          parsed.aihe has this character string inside (from couchdb)

                          FUNCTION Hoi AS C(msg AS C)#Hoi = "Hello, " + msg#END FUNCTION

                          Comment


                          • #14
                            Re: How to execute a block of code in a variable

                            Originally posted by Ray in Capetown View Post
                            Thanks Stan. I didn't know that. Actually I modified a standard browse right click menu, retained the delete adding password protection and some new options
                            I think you need to process the script one line at a time.

                            Code:
                            scr = <<%tst%
                            ui_msg_box("Step1","This is line 1.")
                            ui_msg_box("Step2","This is line 2.")
                            ui_msg_box("Step3","This is line 3.")
                            %tst%
                            
                            ? scr
                            = ui_msg_box("Step1","This is line 1.")
                            ui_msg_box("Step2","This is line 2.")
                            ui_msg_box("Step3","This is line 3.")
                            
                            
                            for each ln in scr
                            evaluate_template(ln.value)
                            next
                            There can be only one.

                            Comment


                            • #15
                              Re: How to execute a block of code in a variable

                              Originally posted by Ray in Capetown View Post
                              More or less Tim
                              I guess there is no generally known function to execute a codeblock as is.
                              I can strip the !+space out, convert all -"- to -\"-, separate the lines for each... but some of the code line structures dont work with evaluate_template.
                              For the short term to resolve the issue, I will write all the code options into a script and use GOTO to run the relevant one.
                              Could you give an example of code that did not work in evaluate template?
                              Tim Kiebert
                              Eagle Creek Citrus
                              A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                              Comment

                              Working...
                              X