type StructTest = object strVal: string #lazy tricks proc pause() = var x = readLine(stdin) #testing #void proc do1()= echo "doing a" #void advanced !!! proc do2(parStrIn: string) = var tmpStruct: StructTest tmpStruct.strVal = parStrIn echo tmpStruct.strVal #string proc do3(): string = "doing c" #proc do4(): StructTest = # ? #tried this and more ... proc do4(parStructTestIn: StructTest): StructTest = var rtStructTest: StructTest rtStructTest.strVal = "doing d" #parStructTestIn = rtStructTest # brain stole compiler > cannot be assigned #parStructTestIn.strVal = rtStructTest.strVal # same brain damage do1() do2("doing b") echo do3() var test4: StructTest do4(test4) pause()
proc do4(parStructTestIn: var StructTest): StructTest =
When you want to modify a proc parameter and return that modified value, you have to mark it with var. Or, when you want to modify it only inside the proc, you may make a local copy, which may have the same name. And, when your proc should return a value, you may need an assignment to a special variable named result or you have to use an return statement. See the tutorial and the manual.
proc do4(): StructTest = result.strVal = "what ever.. now does work" and can now even do: echo do4().strVal