Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Return Objects
#1
I looked on the forum and checked if there was any post that is like what i want, but i couldn't find one. I want to make a function return objects. I was reading up on the "ret" command and it says i should not return a string or an array. I am not able to create a function that declares all the objects and call them into a function because usually i am unable to get the window right away.

Example: I am using Microsoft Word and write a few words in the beginning using the default black, but later in the same macro i want to write text in a different color. So i hit change text color button and i have to call in this function to get the accessible objects from the Color Window. How would i go about returning "OK", "DefineColor", and "CloseColor" objects i made?
Code:
Copy      Help
IStringMap m=CreateStringMap

int w=win("Color" "#32770")
Acc a.Find(w "WINDOW" "Color" "class=#32770" 0x1005)

ARRAY(Acc) l
Acc OK DefineColor CloseColor
str role name
str data
int x y cx cy i

a.GetChildObjects(l -1)
for i 0 l.len
,l[i].Role(role)
,name=l[i].Name
,l[i].Location(x y cx cy)
,if role="PUSHBUTTON"
,,if name="OK"
,,,m.IntAdd("OK" i)
,,,OK=l[i]
,,if name="Define Custom Colors >>"
,,,m.IntAdd("Define" i)
,,,DefineColor=l[i]
,,if name="Close"
,,,m.IntAdd("Close" i)
,,,CloseColor=l[i]
,data.formata(" %i : %s : %s : %i %i %i %i[]" i role name x y cx cy)
#2
Function MyFunctionThatReturnsSeveralAcc
Code:
Copy      Help
;/
function Acc&OK Acc&DefineColor Acc&CloseColor


OK=0; DefineColor=0; CloseColor=0 ;;clear the variables, in case the variables are already set and this function will not set them for some reason

IStringMap m=CreateStringMap

int w=win("Color" "#32770")
Acc a.Find(w "WINDOW" "Color" "class=#32770" 0x1005)

ARRAY(Acc) l
str role name
str data
int x y cx cy i

a.GetChildObjects(l -1)
for i 0 l.len
,l[i].Role(role)
,name=l[i].Name
,l[i].Location(x y cx cy)
,if role="PUSHBUTTON"
,,if name="OK"
,,,m.IntAdd("OK" i)
,,,OK=l[i]
,,if name="Define Custom Colors >>"
,,,m.IntAdd("Define" i)
,,,DefineColor=l[i]
,,if name="Close"
,,,m.IntAdd("Close" i)
,,,CloseColor=l[i]
,data.formata(" %i : %s : %s : %i %i %i %i[]" i role name x y cx cy)

how to call the function
Macro Macro1785
Code:
Copy      Help
Acc OK DefineColor CloseColor
MyFunctionThatReturnsSeveralAcc OK DefineColor CloseColor

out OK.Name
#3
Thank you very much Gintaras.


Forum Jump:


Users browsing this thread: 1 Guest(s)