Announcement

Collapse
No announcement yet.

Execute magic code when a specific form gets activated

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

  • Execute magic code when a specific form gets activated

    In my project i have form 0 to 5, I start with Form 0 and based on some action i either display form 4 or 5. Both form 4 and 5 are simple image based forms with no buttons or controls. Now whenever form 4 or 5 loads after 5 seconds i want it to go back to form 0 automatically.

    How can i start a timer on a specific form activation and display another form on timer expiry. I did see Magic code but that seems to execute for all form init.
    If i want to do some initialisation on a specific form init how do i achieve this?

  • #2
    Hello,

    How can i start a timer on a specific form activation and display another form on timer expiry.
    This can be done by creating a Magic Event and attaching it to a button's event. I will attach the ViSi-Genie project
    below but as a prerequisite, you need to read these appnotes first if you haven't yet:

    AN-00199 ViSi-Genie Magic Code Insertion Points

    4D-AN-00182 ViSi-Genie How to Add Magic Objects

    AN-00159 ViSi–Genie Magic Button Counters

    AN-00156 ViSi Genie Magic Main Loop Counter

    Additional resources that should come in very handy are located here:
    ViSi-Genie User Guide
    4DGL Programmer's Reference Manual
    DIABLO16 Internal Functions Manual

    Here's the sample project similar to what you wanted to do:
    ActivateFormThenGoBack.zip

    Should you have any question/s regarding the project, feel free to ask.

    I hope this helps.

    Best regards,
    Sherwin
    Attached Files
    Last edited by sherwin4D; 15 August 2019, 07:59 PM.

    Comment


    • #3
      Hi Sherwin

      Thanks a lot for the detailed response and sample code. I did went through those app notes and it was quite useful but it looks like the information is spread across multiple areas. Your code gave me a good understanding of the magic code use case for this scenario. Thanks again
      Last edited by mk_cs; 16 August 2019, 03:08 AM.

      Comment


      • #4
        sherwin4D Just one more query, if i want to initialise a variable or run some function when a specific form gets activated how do i achieve that?

        I believe we have to create a Magic code, insert in "PreActivateForm" but how do i make sure that the code gets executed only for a specific form number and not for all forms

        Comment


        • #5
          Hi,

          if i want to initialise a variable or run some function when a specific form gets activated how do i achieve that?
          You'd have to create and place your function at Constant/Global/Data Magic Code, e.g.:

          Code:
          var myvar;
          var flag_formN;
          
          func myfunc()
               //do something here
          endfunc
          how do i make sure that the code gets executed only for a specific form number and not for all forms
          To make sure that your function is only executed for a specific form, you could create a flag variable to let your program know
          you're in a specific form. This has been demonstrated in the sample project from my previous post. You'd have to place the
          conditional statement inside the Main Loop Magic Code.

          I hope this has been helpful.

          Good luck and best regards,
          Sherwin
          Last edited by sherwin4D; 20 June 2020, 12:01 PM.

          Comment


          • #6
            Yeah i saw the variable based approach, so the only way to execute code for a specific form init is to have a variable for each form and whenever we call ActivateForm(N) just set the variable before that

            formNactivated := 1;
            ActivateForm (N);


            In the IDE "Object Inspector" when we choose formN->Object formN->Events tab we get "OnActive" option. Right now i can only see "Report Message" i was hoping if we can also get some option to call some Magic event/code it would have been great so that we can start running the code on form activation. This will be especially useful when we want to dynamically scrabble positions of objects or based on current state of certain variables hide/unhide corresponding objects within the form which we are going to display.

            Comment


            • #7
              Hi,

              how do i make sure that the code gets executed only for a specific form number and not for all forms
              A much better way to ensure that you're function will only be executed while in a specific form is to use the Callable Function
              CurrentForm, inside the Magic Code Main Loop:
              Code:
              if (CurrentForm == n)
                  //put your function here
              endif
              For a complete list of Callable Functions you can use with Genie Magic, please refer to ViSi-Genie User Reference Manual. (page 42)

              Kind regards,
              Sherwin
              Last edited by sherwin4D; 16 August 2019, 05:56 PM.

              Comment


              • #8
                Thanks a lot for all the info. Will ping back if i have further queries

                Comment


                • #9
                  Hi,

                  No worries, glad we could help.

                  All the best,
                  Sherwin

                  Comment

                  Working...
                  X