Page 1 of 1

Some of my suggestions return to custom types

Posted: Sun Mar 20, 2016 4:29 pm
by callroot

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure.*myBigStructure foo()

  ProcedureReturn *a
  
EndProcedure 

Re: Some of my suggestions return to custom types

Posted: Sun Mar 20, 2016 4:44 pm
by Julian
You can do it this way, otherwise the scope of myBigStructure would last past the procedure its created in.

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure foo(*test.myBigStructure)
  
  *test\a = 1
  
EndProcedure

Define moo.myBigstructure

foo(@moo)
Debug moo\a

Re: Some of my suggestions return to custom types

Posted: Sun Mar 20, 2016 11:49 pm
by Demivec
You can do it this way also:

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure.i foo() ;*myBigStructure
  Protected *a.myBigStructure
  
  ;structure is created here, it has to be freed by caller
  *a = AllocateStructure(myBigStructure)
  *a\a = 5
  
  ProcedureReturn *a
EndProcedure

Define *b.myBigStructure

*b = foo()
Debug *b\a

FreeStructure(*b)