yes you are right Niels with setValue, only the value is set, not the lines queue.
maybe there is room for a new st.copy or st.clone method that sets the value and copies the lines queue and all the other properties, but it is probably only a few lines of code anyway:
localSt.setValue(globalSt)
localSt.freelines()
loop x = 1 to globalSt.records()
localSt.addLine(globalSt.getLine(x))
end
Yes Geoff, for now I do a loop but it doesn’t look pretty.
I’m sure Bruce has an argument for why things are the way they are, or just something he forgot.
more like something that hasn’t been thought about or requested before.
you can simply write your own function and use that, something like
clone procedure(stringTheory destSt, stringTheory sourceSt)
code
destSt.start()
destSt.setValue(sourceSt)
loop x = 1 to sourceSt.records()
destSt.addLine(sourceSt.getLine(x))
end
! add assignments here for any other properties you want cloned
having done that, because in a class the first parameter is a pointer to the class itself, you can simply write:
localSt.clone(globalSt)
which is perhaps nicer looking than (but equivalent to)
You’re thinking I’ve got these lines in a Queue I want to add so Clone would not be my choice. There’s already an .AddLine() for 1. Based on my own String class I would suggest plural “Lines”:
I think you might be solving a different problem, although that is a neat solution to adding lines.
In this case (as I understood it) Niels was wanting to copy a stringTheory object including (but not limited to) the lines queue, and do it in one statement.
st:lines : The Lines associated with NewValue are copied as well. If this is omitted (the default default) then only the value is copied, not the lines queue as well.
The docs say “Lines … copied”. Does not say what happens if there are existing lines? Are they Free()'d or are the Lines appended to the existing Lines?
Since .SetValue(ST) replaces the existing Value (does not append) it seems like Lines should work the same way … but it’s useful to be able to append Lines which is why I suggested a separate .AddLines(). To merge lines from multiple ST into 1.
they are free()'d first. Basically with st:Lines option you are copying the object’s value AND lines queue. I’ve had some private messages with Bruce about some aspects of it and also mentioned I liked your .AddLines() suggestion.
They are Free’d. I’ll tweak the docs to make that clear. The clue is in the name of the method - SetValue - which sets the value for the object, it doesn’t Append it (that’s the job of the Append method.)
I agree, Append and Prepend can be extended to this purpose. The concept of a copy queue, copying a single field from some queue into the lines queue has been added to the thinking queue. I’m not sure yet if I like that.