Page 1 of 1

Posted: Thu Aug 15, 2002 3:29 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.

How can i send a structure as parameter to a procedure if its created as a thread?

Code: Select all


Structure DATOS
name.s
lastname.s
country.s
numid.l
EndStructure

Procedure genera(*myvar.DATOS)
  MessageRequester("01",*myvar\name,0)
  MessageRequester("02",*myvar\lastname,0)
  MessageRequester("03",*myvar\country,0)
  MessageRequester("04",Str(*myvar\numid),0)
EndProcedure

myvar.DATOS
myvar\name = "MyName"
myvar\lastname = "MyLastName"
myvar\country = "MyCountry"
myvar\numid = 101

;works fine in this way
genera(@myvar)

;in this way i cant make it runs, iv tried several possibles ways and fails everytime

;ThreadID.l = CreateThread(@genera(),@myvar)

End


Posted: Thu Aug 15, 2002 5:12 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Your program is ending right after
starting the thread.
If the program is ended, the threads are
also destroyed.

Try this, so you have 10 seconds:

Code: Select all

Structure DATOS
name.s
lastname.s
country.s
numid.l
EndStructure


Procedure genera(*myvar.DATOS)
  MessageRequester("01",*myvar\name,0)
  MessageRequester("02",*myvar\lastname,0)
  MessageRequester("03",*myvar\country,0)
  MessageRequester("04",Str(*myvar\numid),0)
EndProcedure


myvar.DATOS
myvar\name = "MyName"
myvar\lastname = "MyLastName"
myvar\country = "MyCountry"
myvar\numid = 101


ThreadID = CreateThread(@genera(),@myvar)


Delay(10000)


End
See what i mean ??

There _should_ be a command to check if the thread
is still running ( IsThread() / IsThreadRunning() ),
but i cant find it in PureBasic.

It makes more sense with Windows GUI interface:

Code: Select all

Structure DATOS
  name.s
  lastname.s
  country.s
  numid.l
EndStructure


; Thread
Procedure Scroller(*myvar.DATOS)
 TextLength = Len(*myvar\name)
 Repeat
   If Scroller_Position < TextLength + 1 And Scroller_Direction = 0
      Scroller_Position+1
   Else
      Scroller_Direction = 1
      Scroller_Position-1
      If Scroller_Position = 0 : Scroller_Direction = 0 : EndIf
   EndIf
   TEMP$ = Right(*myvar\name,Scroller_Position)
   SetWindowText_(*myvar\numid, TEMP$)
   Delay(200)
 ForEver
EndProcedure


myvar.DATOS
myvar\name  = "MyName"
myvar\numid = OpenWindow(0, (GetSystemMetrics_(#SM_CXSCREEN)-400)/2,(GetSystemMetrics_(#SM_CYSCREEN)-100)/2, 400, 100, #PB_Window_SystemMenu,"")


CreateThread(@Scroller(),@myvar)


Repeat:Until WaitWindowEvent() = #PB_EventCloseWindow
So you can see better that it works...

cya,
...Danilo

(registered PureBasic user)


Edited by - Danilo on 15 August 2002 06:15:21

Posted: Thu Aug 15, 2002 5:57 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Clap, clap, clap, clap...

You are a magician !!!

Thanks my fiend