• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Help getting text from clipboard and copying it back

I need to click on a button and get the text that is in the clipboard and copy it to a string  (MyString: string)
Then my program alters MyString and immediately puts it back into the clipboard.
I need it  to be able to get more than 255 characters from/to the clipboard.

What I'm trying to do is simply change the return/linefeed characters to something else and copy the modified data back to clipboard.
0
Gwena
Asked:
Gwena
  • 6
  • 6
  • 2
1 Solution
 
MotazCommented:
Uses:
ClipBrd

On button's OnClick event:

var
  MyStr: string;
begin
  MyStr := ClipBoard.AsText;

Motaz
0
 
MotazCommented:
the returning Value (MyStr) is a long Delphi string, and you can change it then you can assign the value again to the cliboard:

var
  MyStr: string;
begin
  MyStr := ClipBoard.AsText;
  for i:= 1 to Length(MyStr) do
   if MyStr[i] = #13 then
    MyStr[i]:= #YourChar;

  ClibBoard.AsText:= MyStr;
end;

Motaz

0
 
GwenaAuthor Commented:
Hi Motaz :-)

the astext can only get 255 chars... I need to get more than that.
I'm thinking that SetTextBuf and GetTextBuf
may be what I need... but I need an example of using them to get the clipboard and put it into a string and vice versa.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
MotazCommented:
Who told you that it can get only 255 characters? it can return unlimited size of string.

What version of Delphi did you have?

I test it with Delphi 5 and it returns more than 255 characters.

If it didn't work for you please post here the code of reading and setting the clipboard

Motaz
0
 
GwenaAuthor Commented:
Hi Motaz :-)

Your code seems to work!
The help file in delphi says that astext
will ONLY work up to 255 chars... I guess they
goofed huh ;-)  here is what delphi help says

"The string value of the AsText property is limited to 255 characters. If you need to set and retrieve more than 255 characters, use the SetTextBuf and GetTextBuf Clipboard methods."

So... I wonder how big a text string I could handle using this method?  I will check it out tomorrow..it's getting very late ;-)
0
 
GwenaAuthor Commented:
Adjusted points from 50 to 75
0
 
GwenaAuthor Commented:
Thanks Motaz... you really helped me here..
I have upped the points a wee bit :-)
0
 
shenqwCommented:
try
  Clipboard.GetTextBuf;
  Clipboard.SetTextBuf
0
 
MotazCommented:
I'm not sure exactly but I think it is limited by computer memory (Vertual memory) but it will not exceed 2 G Bytes

Motaz
0
 
shenqwCommented:
try
  Clipboard.GetTextBuf;
  Clipboard.SetTextBuf
0
 
MotazCommented:
Thanks very much
Motaz
www.geocities.com/motaz1
0
 
GwenaAuthor Commented:
Nice web site Motaz

The Ebook and the file encrypter program look interesting :-)

...Gwen..
0
 
MotazCommented:
I also visit your homepage, but is the EasyIP only get the local computer IP address?
0
 
GwenaAuthor Commented:
Hi Motaz

Yes it only gets the local ip... it's a very simple little program.
I put the source at the web site too.

...Gwen..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now