Page 1 of 2

Variables ( Solved )

Posted: Sat Sep 05, 2009 4:46 pm
by lailton.webmaster
MyArray:={ {'campo1', 30}, {'campo2', 50}}

for n = 1 to len(MyArray)

// How make it ?
// #define MyArray[n][1] MyArray[n][2]

next n

msginfo(campo2) // need return 50

i maked it

// it´s OK more is define campo2 as 50 only inside this function when i try msginfo(campo2) in other function
// give me erro variable no exist.
&( " "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

i try make it too.

&( "Public "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

More give me erro.

Someone can help ?

thanks

Re: Variables

Posted: Sat Sep 05, 2009 8:21 pm
by Enrico Maria Giordano
Sorry, I don't understand what you're trying to do. Can you rephrase your question?

EMG

Re: Variables

Posted: Sat Sep 05, 2009 8:41 pm
by lailton.webmaster
METHOD Events() CLASS MyActiveX
local act, oReg, cTypeLib, aEvents

oReg := TReg32():New( HKEY_CLASSES_ROOT, "CLSID\" + ::cString + "\InprocServer32" )
cTypeLib := oReg:Get( "" )
oReg:Close()
act:=TactiveX():new(::Janela, ::cString,0,0,0,0)
if ! Empty( cTypeLib ) .and. File( cTypeLib )
aEvents = ActXEvents( cTypeLib, act:hActiveX )
endif
for n = 1 to len(aEvents)
#define aEvents[n][1] aEvents[n][2] // problem aqui :) no stay defined ...
next n

Return nil

Re: Variables

Posted: Sat Sep 05, 2009 8:43 pm
by lailton.webmaster
other sample

MyArray:={ {'campo1', 30}, {'campo2', 50},{'kakaka',100},{'mouseon',20},{'click',-12} }
// this Array i receive in function ActEvents of fivewin. it´s only sample. no return always same array.

for n = 1 to len(MyArray)

#define MyArray[n][1] MyArray[n][2]
next n

:lol:

Re: Variables

Posted: Sat Sep 05, 2009 8:57 pm
by Enrico Maria Giordano

Code: Select all

FUNCTION MAIN()

    LOCAL aArray := { { "SYMBOL1", 10 }, { "SYMBOL2", 20 } }

    LOCAL i

    FOR i = 1 TO LEN( aArray )
        &( "M -> " + aArray[ i, 1 ] + " := " + LTRIM( STR( aArray[ i, 2 ] ) ) )
    NEXT

    ? M -> SYMBOL1
    ? M -> SYMBOL2

    RETURN NIL
EMG

Re: Variables

Posted: Sat Sep 05, 2009 11:22 pm
by lailton.webmaster
DOnt have other code ?

that dont need add M-> VAr ?

and i need too call this var in a function OutSide this method.

thanks

Re: Variables

Posted: Sun Sep 06, 2009 9:12 am
by Enrico Maria Giordano
I don't understand, sorry.

EMG

Re: Variables

Posted: Sun Sep 06, 2009 4:21 pm
by James Bott
In order to see data outside the class it has to be defined as data of the class.

Code: Select all

class myActiveX
   data aEvents
   ...
endclass

Now you can access aEvents:

MsgInfo( oActiveX:aEvents[1][1] )

MsgInfo( oActiveX:aEvents[1][2])
You cannot use #DEFINE to define data of the class.

Or, if you want to make a class for each type of ActiveX that you are using, then you can define all the event names as data of the class, then you can assign the values to them when the object is initialized. Then you can access each event from outside the class.

Code: Select all

// ActiveX calendar class
CLASS calendar from TActiveX
   DATA Campo1
   DATA Campo2
endclass

Method new()
   ...
   aEvents = ActXEvents( cTypeLib, act:hActiveX )
   ::Campo1 := aEvents[1][2]
   ::Campo2 := aEvents[2][2]
   ...
return self

oCalendar := calendar():new()

msgInfo( oCalendar:Campo1 ) // returns value, e.g. 30
James

Re: Variables

Posted: Sun Sep 06, 2009 4:28 pm
by James Bott
Here is another way you could do it. Create a method getEvent() and pass it the name of the event to get the value.

Code: Select all

method getEvent( cEvent )
  local uValue, i
  cEvent:= upper(alltrim(cEvent))
  for i=1 to len( ::aEvents )
     if upper(::aEvents[i]) == cEvent
        uValue:= ::aEvents[i][2]
     endif
  next
return uValue

msgInfo( oCalendar:getEvent("campo1") )  // returns 30
James

Re: Variables

Posted: Sun Sep 06, 2009 6:04 pm
by lailton.webmaster
Good James

thanks

Re: Variables

Posted: Sun Sep 06, 2009 6:15 pm
by James Bott
If you haven't already read them, there are some articles on writing FW classes on my website at http://www.gointellitech.com.

James

Re: Variables

Posted: Tue Sep 08, 2009 12:57 am
by fraxzi
lailton.webmaster wrote:MyArray:={ {'campo1', 30}, {'campo2', 50}}

for n = 1 to len(MyArray)

// How make it ?
// #define MyArray[n][1] MyArray[n][2]

next n

msginfo(campo2) // need return 50

i maked it

// it´s OK more is define campo2 as 50 only inside this function when i try msginfo(campo2) in other function
// give me erro variable no exist.
&( " "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

i try make it too.

&( "Public "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

More give me erro.

Someone can help ?

thanks
To get the value 50 on the second element of second sub-element is like this (as I understand your code):

....
LOCAL aX

MyArray:={ {'campo1', 30}, {'campo2', 50}}

FOR EACH aX IN MyArray
IF aX[2] == 50 //second sub element of MyArray var
msginfo( aX[1] ) //as 'campo2'
msgInfo( aX[2] ) //as 50
END
NEXT
.....


Regards,
Frances

Re: Variables

Posted: Tue Sep 08, 2009 1:30 am
by James Bott
Frances,

That may work but assigning value to PUBLICs inside a class is not good OOP practice. It kind of defeats the purpose of having a class. The data should be stored inside the class.

Regards,
James

Re: Variables

Posted: Tue Sep 08, 2009 3:09 am
by lailton.webmaster
THanks

I did how James Bott say me.

i created method GetEvent

:) to be perfect.

thanks :)

Re: Variables

Posted: Tue Sep 08, 2009 3:26 am
by fraxzi
James Bott wrote:Frances,

That may work but assigning value to PUBLICs inside a class is not good OOP practice. It kind of defeats the purpose of having a class. The data should be stored inside the class.

Regards,
James

Thanks for the Idea. Best solution.