using Function twice with Object as Parameter ?

Post Reply
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

using Function twice with Object as Parameter ?

Post by Jimmy »

hi,

i do want to use Thread which are call a Function.
i use Thread to "fill" Imagelist of Object and all in Function use Object ... except FOR ii

Question : will ii be "manipulate" by 2nd Thread when called twice :?:
greeting,
Jimmy
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: using Function twice with Object as Parameter ?

Post by James Bott »

Jimmy,

I'm not sure I understand what you want to do but here is an example of adding a new sale amount to a oCustomer object using a function. Note that a customer object exists until you end it.

Code: Select all | Expand

Function addSale( oCustomer, nNewSale )
   oCustomer:TotalSales := oCustomer:TotalSales: + nNewSale
Return nil
However, this type of function should be made into a Method of the oCustomer object, then you can do this:

Code: Select all | Expand

oCustomer:AddSale( nSale )

? oCustomer:TotalSales
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: using Function twice with Object as Parameter ?

Post by Jimmy »

hi James,

thx for Answer

to use a Function twice (or more) is not Problem ... IF Function is "short" and "quick"

but i have to do a lot in Function and have a Variable "ii" in a FOR / NEXT

Code: Select all | Expand

   FOR ii := 1 TO nMax
    cFilename := TRIM( ::aSource[ ii ] [ F_NAME ] )
as i have 2 x TGrid() which each start a Thread so both "may" use Function at "same Time"
but what if Thread 1 is at ii = 99 and 2nd Thread start at ii = 1 :?:

---

my "Problem" was while i use a CLASS and can not call a Method using hb_threadStart()

Code: Select all | Expand

   hb_threadStart(@::MyMethod)
   hb_threadStart(@oSelf:MyMethod)
   hb_threadStart(@&MyMethod)
all of them fail ...

so i use a Function which work but i´m not sure if it is "safe" this Way

now i found a Solution to use a Method "in" CLASS when using hb_threadStart()

Code: Select all | Expand

   bMethod := { || ::ImageThread() }
   ::hThread := hb_threadStart( HB_BITOR( HB_THREAD_INHERIT_PUBLIC, HB_THREAD_MEMVARS_COPY ), @bMethod )
i "think" that this is "safe" as each Object have its own Instance so Variable are not "visible Outside"
greeting,
Jimmy
Post Reply