Board index » delphi » Copying large amounts of "text" to the clipboard

Copying large amounts of "text" to the clipboard

Hi ,

I've been struggling with a problem for a while and so thought I'd,
hopefully, draw on the combined knowledge in this group.
I have an array of reals that I want to put on the clipboard. The
reason for doing this is so that I can then copy the "data" into a
spreadsheet.
The data consists of more that 255 characters - this is the basis of my
problem as Delphi strings are limited to 255 chars. I've dabbled with
buffers (GetTextBuf) and tried putting lines of the array into lines of
a memo - both unsuccessfully - possibly due to my lack of
understanding?!
Anyway, I imagine that I am not alone in trying to put data onto the
clipboard, so if some kind sole has a solution I would be grateful.

Cheers

Aly
a.d.gill...@st-and.ac.uk

 

Re:Copying large amounts of "text" to the clipboard


        a...@st-and.ac.uk (Alastair Gillies) wrote:

Quote
>Hi ,

>I've been struggling with a problem for a while and so thought I'd,
>hopefully, draw on the combined knowledge in this group.
>I have an array of reals that I want to put on the clipboard. The
>reason for doing this is so that I can then copy the "data" into a
>spreadsheet.
>The data consists of more that 255 characters - this is the basis of my
>problem as Delphi strings are limited to 255 chars. I've dabbled with
>buffers (GetTextBuf)

        Sounds like you're close. If you have a bunch of text in a PChar
you can copy it to the clipboard with ClipBoard.SetTextBuf(thePChar) .

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:Copying large amounts of "text" to the clipboard


I have a similar problem, I am loading a "large" (over 255 chars) of text
into a PChar variable, then trying to get it into a TMemo field.  When I
peek at the contents of the PChar, everything seems to be there, and when
I use the SetTextBuf the first time, it seems to work just fine.  On
subsequent attempts, however, I get nothing - if I TMemo1.Clear first, it
stays cleared, if I don't, it just leaves the first set of data in there.
For example, the following doesn't work for any but the first call ...
(LoadTextString has the 4,000 or so characters, it was StrMem'd in another
area).

          GlobalLock(THandle(LoadTextString));
          TMemo1.Clear;                   {This should be unnecessary}
          TMemo1.SetTextBuf(LoadTextString);
          TMemo1.Refresh;                {This is to update the display}
          GlobalUnLock(THandle(LoadTextString));
          FreeMem(LoadTextString,SizeOf(LoadTextString));

Like I said, when I peek at the contents of LoadTextString it has the
information I want - even on calls where this code fails to load the
TMemo.

Very frustrated here in Northfield MN...

Re:Copying large amounts of "text" to the clipboard


Quote
maratho...@aol.com (MARATHON99) wrote:
>I have a similar problem, I am loading a "large" (over 255 chars) of text
>into a PChar variable, then trying to get it into a TMemo field.  When I
>peek at the contents of the PChar, everything seems to be there, and when
>I use the SetTextBuf the first time, it seems to work just fine.  On
>subsequent attempts, however, I get nothing - if I TMemo1.Clear first, it
>stays cleared, if I don't, it just leaves the first set of data in there.
>For example, the following doesn't work for any but the first call ...
>(LoadTextString has the 4,000 or so characters, it was StrMem'd in another
>area).

>          GlobalLock(THandle(LoadTextString));
>          TMemo1.Clear;                   {This should be unnecessary}
>          TMemo1.SetTextBuf(LoadTextString);
>          TMemo1.Refresh;                {This is to update the display}
>          GlobalUnLock(THandle(LoadTextString));
>          FreeMem(LoadTextString,SizeOf(LoadTextString));

>Like I said, when I peek at the contents of LoadTextString it has the
>information I want - even on calls where this code fails to load the
>TMemo.

        Is LoadTextString a PChar? Assuming it is, what should be unnecessary
is the GlobalLock/Unlock business - try just leaving it out.

        Actually I don't follow any of this - if LoadTextString is a PChar
then I'm surprised the typecast THandle(LoadTextString) works. If OTOH
LoadTextString is a global memory handle then the GlobalLock function should
_return_ a pointer, but you're not doing anything with the return value, you're
just ignoring it. ??? Anyway, if it's a PChar then try leaving out the Global
stuff and see what happens.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads