Copying a stringtheory object into another object - object containing lines

Hi

I would like to copy the complete Stringtheory object into another object.
Normally I do this:

localSt.SetValue(globalSt)

But this way doesn’t copy the lines.
How do I get all the lines into the object?
Of course I can make a loop but…

Regards Niels

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

cheers

Geoff R

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)

clone(localSt, globalSt)

hth and cheers

Geoff R

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”:

.AddLines(StringTheory stWithLines)

.AddLines(*QUEUE QwithLines, *? QlineField, BOOL pClip=True)

Hi Carl

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.

cheers

Geoff R

1 Like

I’ve made a build 3.50 which should work for you. Your code becomes;

localSt.SetValue(globalSt,st:lines)

See StringTheory Complete Documentation for details.

2 Likes

Fantastic Bruce. Thanks!

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.

Qtheory might be the next big thing

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.

MaxQueue is to Queues what StringTheory is to Strings.
https://www.capesoft.com/accessories/maxqueuesp.htm

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.