Page 1 of 1

When a structure is born, set automatic values?

Posted: Tue Feb 17, 2009 10:08 pm
by Seymour Clufley

Code: Select all

Structure demostructure
  token.s
EndStructure


Procedure.b InitializeDemoStructure(*struc.demostructure)
  ; this procedure fills the token field in a demostructure with some random letters
  ; I'm looking for a way to automatically call this procedure whenever an instance of demostructure is first made
  
  *struc\token = ""
  For a = 1 To 8
      *struc\token+Chr(Random(25)+65)
  Next a
  
EndProcedure


Procedure DoSomething(*ds.demostructure)
  
  ; this procedure uses an instance of the demostructure
  
EndProcedure


test1.demostructure
Debug "test1's token is "+test1\token

DoSomething(@test2.demostructure)
Debug "test2's token is "+test2\token
Is that just pie in the sky?

Posted: Tue Feb 17, 2009 10:19 pm
by greyhoundcode
Looks like a job for a constructor method :wink:

Posted: Tue Feb 17, 2009 11:09 pm
by Fluid Byte
I didn't find a solution for procedures parameters but for local variables:

Code: Select all

Procedure.s RandomHash()
	For c = 1 To 8
	   temp$ + Chr(Random(25)+65)
	Next
	ProcedureReturn temp$
EndProcedure 

Structure _demostructure
  token.s
EndStructure

Macro demostructure
	_demostructure\token = RandomHash()
EndMacro

test1.demostructure
test2.demostructure
test3.demostructure

Debug test1\token
Debug test2\token
Debug test3\token
Maybe it can get you started.