using Function twice with Object as Parameter ?

using Function twice with Object as Parameter ?

Postby Jimmy » Mon Feb 27, 2023 4:27 am

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
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: using Function twice with Object as Parameter ?

Postby James Bott » Mon Feb 27, 2023 8:32 pm

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 view
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 view
oCustomer:AddSale( nSale )

? oCustomer:TotalSales


James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: using Function twice with Object as Parameter ?

Postby Jimmy » Tue Feb 28, 2023 5:32 am

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 view
  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 view
  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 view
  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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 84 guests