Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all
i tried to "improve" the now well known Firefox4GetTabs function.
To fit my needs, i'd like to sum some tabs properties directly in a variable, and use what i need in time.
But i fail to find the right syntax. Little push needed here.
What i did, but do not work.....
in calling macro
type TABPROP str'name str'url int'index (and some more)
ARRAY(TABPROP) tabs
int selectedTab=Firefox4GetTabs(0 tabs)
--------------------------------------------------
modified Firefox4GetTabs function
function# hwndFF ARRAY(TABPROP)&tabs
** need tabs initialization here
if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) ret -1
enum tabs
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
rep
if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
tabs[].name=a.Name
get selected tab
if(r<0 and a.State&STATE_SYSTEM_SELECTED) tabs[].index=i
.......
a.Navigate("n"); err break
i+1
enum panes
a.Find(hwndFF "DOCUMENT" "" "" 0x3011 2 0 "pa3fi")
rep
get id of this pane, and find in ap
fn.FromAcc(a); _s=fn.Attribute("id")
for(i 0 ap.len) if(ap[i]=_s) break
if(i=urls.len) goto next2 ;;should never happen
get url and store in urls[i]
Acc aa; a.Navigate("fi2" aa)
tabs[].url=a.value
.....
a.Navigate("n"); err break
etc etc
I think you get the picture...
Thanks
Posts: 12,087
Threads: 142
Joined: Dec 2002
Your code is correct, what does not work?
My last FirefoxGetTabs version gets Acc objects of all tab buttons and documents. After calling it you can get their properties. Then don't need to modify the function.
Posts: 12,087
Threads: 142
Joined: Dec 2002
Maybe not correct. I see always tabs[]. It adds new element. To use existing elements, must be tabs[i], where i is an array element index variable.
Posts: 795
Threads: 136
Joined: Feb 2009
the first noticable error is raising a type mismatch from calling function
int selectedTab=Firefox4GetTabs(0 tabs)
QM stop with type mismatch here
function# hwndFF ARRAY(TABPROP)&tabs
Posts: 12,087
Threads: 142
Joined: Dec 2002
Cannot be error here. Maybe you call a wrong function. Also try to restart QM.
this code works
Macro Macro1672
type TABPROP str'name str'url int'index ;;(and some more)
ARRAY(TABPROP) tabs
int selectedTab=Function208(0 tabs)
Function Function208
function# hwndFF ARRAY(TABPROP)&tabs
Posts: 795
Threads: 136
Joined: Feb 2009
OK, restarting QM did it, strange behavior.
Now: calling function
type TABPROP str'name str'url int'index
ARRAY(TABPROP) tabs
OngletsFirefoxType(0 tabs)
for _i 0 tabs.len
out tabs[_i].name
out "==========================="
for _i 0 tabs.len
out tabs[_i].index
if(!tabs[_i].index)
out tabs[_i].name
out "------------"
function# hwndFF ARRAY(TABPROP)&tabs
if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) ret -1
int i=0
int r=-1
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
rep
if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
tabs[].name=a.Name
if(r<0 and a.State&STATE_SYSTEM_SELECTED) tabs[].index=i
next
a.Navigate("n"); err break
i+1
output :
===========================
google.fr
===========================
google.fr
===========================
google.fr
===========================
google.fr
===========================
0
------------
0
------------
2
empty, should be google.fr here as it is the third tab selected - why empty????
------------
0
------------
Posts: 12,087
Threads: 142
Joined: Dec 2002
Don't know, but I see two tabs[] in single loop...
The best way to add/set elements of such array is:
rep
,TABPROP& x=tabs[] ;;adds new element and gets reference to it
,;now set members of the element
,x.name=...
,x.index=...
,...
Posts: 795
Threads: 136
Joined: Feb 2009
yes, two tabs[] because this is the way i found to add name and index in
a new array item, like
ARRAY(str) aa
for i 0 2
aa[]="sometext"
out aa
sometext
sometext
sometext
maybe adding record in a custom type array is only doable by pointers like you showed me?
Posts: 12,087
Threads: 142
Joined: Dec 2002
without pointer would be
rep
,TABPROP x
,x.name=...
,x.index=...
,...
,tabs[]=x ;;add new element and copy x to it
Posts: 12,087
Threads: 142
Joined: Dec 2002
Some examples of working with arrays, for learning or quick reference:
Macro Macro1673
When you type the last . , it shows a list with examples.
I see in Help no such examples, will need to add.
Posts: 795
Threads: 136
Joined: Feb 2009
function hwndFF ARRAY(TABPROP)&tabs
if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) ret -1
TABPROP& x
int i=0
int r=-1
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
rep
if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
x=tabs[]
x.name=a.Name
if(r<0 and a.State&STATE_SYSTEM_SELECTED) x.index=i
next
a.Navigate("n"); err break
i+1
and the calling function no longer works, eg no output at all.
Posts: 12,087
Threads: 142
Joined: Dec 2002
To initialize a reference variable, there are two ways.
1. Declare and assign in single statement:
TABPROP& x=something
2. Assign later, using operator &:
&x=something
Posts: 12,087
Threads: 142
Joined: Dec 2002
If no error at x=tabs[], maybe there is err+ somewhere later in the function. When creating/debugging a function, don't use it, because then you don't see errors.
Posts: 795
Threads: 136
Joined: Feb 2009
function hwndFF ARRAY(TABPROP)&tabs
if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) ret -1
TABPROP& x=0
int i=0
int r=-1
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
rep
if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
x=tabs[]
x.name=a.Name <=================== using debugger (f5) the function goes to the last line of code (err+ ret -1) when reaching this line. Why?
........
err+ ret -1
Posts: 12,087
Threads: 142
Joined: Dec 2002
Error because the reference variable is not initialized. Read my last 2 posts.
Posts: 795
Threads: 136
Joined: Feb 2009
i'm dumb....replacing x=tabs[] by &x=tabs[] did it.
Thanks G
Will come back soon with other problems....
Posts: 12,087
Threads: 142
Joined: Dec 2002
It initializes the variable to nothing.
When you initialize a reference variable, it gets address of something, and then it refers to something. Then can be used like a normal variable.
rep
,TABPROP& x=tabs[]
or
TABPROP& x
rep
,&x=tabs[]
|