Page 1 of 1

revBrowser Question

Posted: Sun Aug 21, 2016 10:33 am
by montymay
Hello forum readers:

I have a card on which I want to display different PDFs. On the card I have different buttons that upon clicking will open a particular PDF. I could put the following script on each button (note: the line numbers are not part of the script):

Code: Select all

1 global gBrowserID
2 on mouseup
3    resetcard
4    put revBrowserOpenCEF(the WindowID of this stack) into gBrowserID
5    revBrowserSet gBrowserID, "rect", the rect of grc "browser"
6    revBrowserSet gBrowserID, "url", "file:c/path_of_intended_pdf/pdf_file.pdf"
7 end mouseup
8
9 on resetcard
10   repeat for each item gBrowserID in revBrowserInstances()
11     revBrowserClose gBrowserID
12 end resetcard
This technique works, but I am thinking that a skilled programmer can put some code in the card script that will make the repetition of all of the above code (except the path and file name) in each button unnecessary. I am thinking the use of customs commands can make the scripting more elegant, but I don't know how to write it. Is the above technique the only way? I tried putting lines 4 and 5 in the card script, but that does not work.

If it can be done on the card level, can it be done so that different card scripts can call upon a stack script, or different substacks scripts can call upon a mainstack script?
Thanks for your suggestions or answers.

Monty

Re: revBrowser Question

Posted: Sun Aug 21, 2016 3:17 pm
by Klaus
Hi Monty,

maybe you mean something like this?

Put this into the stack script:

Code: Select all

global gBrowserID
command create_browser tRect,tUrl
   resetcard
   put revBrowserOpenCEF(the WindowID of this stack) into gBrowserID
   revBrowserSet gBrowserID, "rect", tRect
   revBrowserSet gBrowserID, "url", tUrl
end create_browser

on resetcard
   repeat for each item gBrowserID in revBrowserInstances()
      revBrowserClose gBrowserID
   end repeat
end resetcard
Then you can call it from every card of every (sub-)stack by just passing the rect and url like this:

Code: Select all

on mouseup
   put the rect of grc "browser" into tRect
   put "file:///c:/path_of_intended_pdf/pdf_file.pdf" into tUrl
   create_browser tRect,tUrl
end mouseup
Best

Klaus

Re: revBrowser Question

Posted: Mon Aug 22, 2016 2:51 am
by montymay
Hi Klaus:

I knew there was a way. Thanks for much for the answer.

Monty

Re: revBrowser Question

Posted: Mon Aug 22, 2016 6:51 pm
by jacque
repeat for each item gBrowserID in revBrowserInstances()
I've never used a global as the iterator variable. Does it work?

Re: revBrowser Question

Posted: Mon Aug 22, 2016 7:08 pm
by dunbarx
Jacque.

if I glean what you noticed, does this help" Make a button. In the button script:

Code: Select all

global XYZ

on mouseUp
   put 1 into XYZ
   put "1,2,3,4,5" into temp
   repeat for each item XYZ in temp
   end repeat
   answer XYZ
end mouseUp
The global loads without complaint, and retains its final value.

Craig

Re: revBrowser Question

Posted: Mon Aug 22, 2016 9:06 pm
by jacque
@DunbarX: Yes, but it destroys the original value of the global. That may or may not be the desired result, depending on what it impacts in other scripts. I guess for the OP's use it doesn't matter but I don't think I'd do that for general use.

Re: revBrowser Question

Posted: Mon Aug 22, 2016 9:25 pm
by dunbarx
Jacque.
but it destroys the original value of the global.
Understood. But that is a choice, no? That said, assuming the use of globals is understood, I, too, see no reason to ever use one as the OP did. I would, depending on whatever shenanigans a handler might be up to, change its value explicitly at the end, derived from a local iterating variable, as you say.

I only ran the test to make sure what I thought would happen actually did. Gloabls are just variables, after all.

Craig