FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour using Function twice with Object as Parameter ?
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
using Function twice with Object as Parameter ?
Posted: Mon Feb 27, 2023 04: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: using Function twice with Object as Parameter ?
Posted: Mon Feb 27, 2023 08: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 (fw): Select all Collapse
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 (fw): Select all Collapse
oCustomer:AddSale( nSale )

? oCustomer:TotalSales
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: using Function twice with Object as Parameter ?
Posted: Tue Feb 28, 2023 05: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 (fw): Select all Collapse
   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 (fw): Select all Collapse
   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 (fw): Select all Collapse
   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

Continue the discussion