0

I have a vector of Strings from a TListView control. I want to copy them to the clipboard, then paste them into a TMemo control such that each line from the list is on a separate line in the TMemo. Everything I've tried so far pastes as a single line. But copy/paste multiple lines within the TMemo itself works just fine. Ideas?

Thanks!

  • "vector of Strings" - do you mean a StringList ? Can you add the code that doesn't work to your question. That way helpful people may be able to offer you "ideas".... Why are you doing this operation via the clip board? – Roger Cigol Nov 23 '21 at 13:07
  • We start with a std::vector of Strings in an app (call it the 'source'). We want to copy those strings to another application that uses a TMemo. We're trying to put the strings into a single String to pass to the clipboard, something like... ` String s; BOOST_FOREACH(String str, strings) { s += str + 0x0d + 0x0a; } cb->SetTextBuf(s.c_str()); ` We assume there's some separator that the TMemo will interpret as the next line, but we haven't found the right one yet. Of course we're not certain that a separator is the problem. Sorry, I don't know how to format code in this editor – user2113260 Nov 23 '21 at 15:04
  • Well without code it's hard. But if "something like" means "exactly like" then the line s += str + 0x0d + 0x0a is wrong - you need to add a string equal to a CR LF pair not these hex constants. TMemo uses CR LF pairs as separators. Remember Strings are all Unicode (wchar_t) in VCL (at least since C++ builder 6.0 days). – Roger Cigol Nov 23 '21 at 15:16
  • @RogerCigol "*Remember Strings are all Unicode (wchar_t) in VCL (at least since C++builder 6.0 days)*" - that is incorrect. The VCL switched to Unicode strings in C++Builder 2009, 8 years after C++Builder 6.0 – Remy Lebeau Nov 23 '21 at 18:14
  • Thanks Remy for your rigor / precision. Tis true I do get which version changed which things mixed up and I appreciate being put right. – Roger Cigol Nov 24 '21 at 09:26

1 Answers1

0

Use the RTL's sLineBreak constant instead of individual chars:

String s;
BOOST_FOREACH(String str, strings) {
    s += (str + sLineBreak);
}

Also, you should be using the TClipboard::AsText property instead of the TClipboard::SetTextBuf() method:

cb->AsText = s;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770