Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARRAY of custom type as parameter
#1
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
#2
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.
#3
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.
#4
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
#5
Cannot be error here. Maybe you call a wrong function. Also try to restart QM.

this code works
Macro Macro1672
Code:
Copy      Help
type TABPROP str'name str'url int'index ;;(and some more)
ARRAY(TABPROP) tabs
int selectedTab=Function208(0 tabs)
Function Function208
Code:
Copy      Help
function# hwndFF ARRAY(TABPROP)&tabs
#6
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
------------
#7
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=...
,...
#8
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?
#9
without pointer would be
rep
,TABPROP x
,x.name=...
,x.index=...
,...
,tabs[]=x ;;add new element and copy x to it
#10
Some examples of working with arrays, for learning or quick reference:
Macro Macro1673
Code:
Copy      Help
_other.__array_examples.
When you type the last . , it shows a list with examples.

I see in Help no such examples, will need to add.
#11
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.
#12
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
#13
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.
#14
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
#15
Error because the reference variable is not initialized. Read my last 2 posts.
#16
i'm dumb....replacing x=tabs[] by &x=tabs[] did it.

Thanks G
Will come back soon with other problems....
#17
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[]


Forum Jump:


Users browsing this thread: 2 Guest(s)