revBrowser Question

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

revBrowser Question

Post by montymay » Sun Aug 21, 2016 10:33 am

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: revBrowser Question

Post by Klaus » Sun Aug 21, 2016 3:17 pm

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

montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Re: revBrowser Question

Post by montymay » Mon Aug 22, 2016 2:51 am

Hi Klaus:

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

Monty

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: revBrowser Question

Post by jacque » Mon Aug 22, 2016 6:51 pm

repeat for each item gBrowserID in revBrowserInstances()
I've never used a global as the iterator variable. Does it work?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: revBrowser Question

Post by dunbarx » Mon Aug 22, 2016 7:08 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: revBrowser Question

Post by jacque » Mon Aug 22, 2016 9:06 pm

@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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: revBrowser Question

Post by dunbarx » Mon Aug 22, 2016 9:25 pm

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

Post Reply