Form RUN/RUNMODAL with OnTimer

Hi All I just ran into a problem with the OnTimer - trigger. I have a form with some calculations in the OnTimer trigger. From here I would like to run another form where the user can input or change some records. The goal is: He should see the results of the changes in the first form. It is a kind of ‘Play - Mode’. It works fine with MyForm.Run. But with this I can’t recognize whether the second form is still opened or not [:(]. Then I tried it with MyForm.RunModal::Action. With this I can recognize whether the second form is still opened or not. But - the OnTimer - trigger of the first form doesn’t work as long as the second form is still opened [:(]. I can’t use Main/Subform in this case! Does somebody have an idea how this dilemma could be solved? bye André

Hi Andre! Here’s a first - untested - idea: Keep a global status variable in the (second) form itself or, if this doesn’t work, in a codeunit. In the OnOpenForm and OnCloseForm triggers of the second form, set this variable to indicate whether the second form is open or not. In the OnTimer trigger of the first form, check this status variable and take appropriate action. As I said: “Untested” [;)]

Hi Heinz Great idea! It works! Thank you. bye André

It did? Really? [;)] Glad to hear that! Did you have to use a codeunit or did it work with a variable in the second form? I was having my doubts about the lifetime of the internal status of objects.

Hi Heinz I solved this by another way. But your idea with the global variable was the clue. I did this with a variable stored in a table. In OnOpenForm of the second form this value is set on ‘Open’/True. With the OnCloseForm I set this value on ‘Close’/False. In OnTimer of the first form I check this value. If this value is false the OnTimer get a False too. Probably not very elegant but it works [8D]. bye André

I just tried my proposed solution with variables both in the second form and in a codeunit. Neither do work [8D] The problem seems to be that on each invocation of the second form, a completely new instance of the object (form/codeunit) is created, with a new set of global variables. But if a codeunit is called repeatedly from e.g. a report, global variables of the CU keep their values between invocations. Looks like some kind of transaction related behavior[?] A table actually seems to be the only solution.

Hi There is still another problem in my case. The first line of my calculation (based on OnTimer) is: ClearAll; Before that I put some variables into the Form.Caption. It’s difficult to handle it with on form but it’s much more difficult with two forms [xx(]. So I decided to go the way by the table. But now it works and it looks fine: The first form jumps from the center to the left corner, the second form is opened below the first form. The user fills the data in the second form. He can see the result immediately in the first form. When the user close the second form the first form jumps from the left corner to his previous place. bye André

You can use a single instance codeunit to create a kind of “system glaobal variable”. The value you want to share should be setup as a global variable in the codeunit and global functions defined in the codeunit to set and read the global variable. These functions can then be called from any object and the single instance nature of the codeunit will maintain the value of the variable.

Hi Jack

quote:


Originally posted by Jack Reynolds
You can use a single instance codeunit to create a kind of “system glaobal variable”. The value you want to share should be setup as a global variable in the codeunit and global functions defined in the codeunit to set and read the global variable. These functions can then be called from any object and the single instance nature of the codeunit will maintain the value of the variable.


Does this variable still have a value after a ClearAll? bye André

Jack, that’s what I tried, but it didn’t work (well, maybe I’m missing something…). You would have to define a variable of type codeunit in each form, and then it seems that there are two instances of this codeunit, each with its own set of global variables.

Andre, ClearAll does not reset a single instance codeunit. The only way that I know of to clear a single instance codeunit is to change to a different company. Heinz, Yes, you do have to declare a variable for the codeunit on each form, but with a single instance codeunit there is only one instance of the codeunit and the variables in each form both have access to that single instance.

Ok, since I can’t find this single instance thing, neither in the codeunit’s nor the variable’s properties, I assume this feature is available only in Attain?