Solved

Help getting text from clipboard and copying it back

Posted on 2000-04-29
14
155 Views
Last Modified: 2010-04-04
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
Comment
Question by:Gwena
  • 6
  • 6
  • 2
14 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2761678
Uses:
ClipBrd

On button's OnClick event:

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

Motaz
0
 
LVL 7

Accepted Solution

by:
Motaz earned 75 total points
ID: 2761714
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
 
LVL 5

Author Comment

by:Gwena
ID: 2761718
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 7

Expert Comment

by:Motaz
ID: 2761729
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
 
LVL 5

Author Comment

by:Gwena
ID: 2761737
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
 
LVL 5

Author Comment

by:Gwena
ID: 2761745
Adjusted points from 50 to 75
0
 
LVL 5

Author Comment

by:Gwena
ID: 2761746
Thanks Motaz... you really helped me here..
I have upped the points a wee bit :-)
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2761747
try
  Clipboard.GetTextBuf;
  Clipboard.SetTextBuf
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2761748
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
 
LVL 3

Expert Comment

by:shenqw
ID: 2761751
try
  Clipboard.GetTextBuf;
  Clipboard.SetTextBuf
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2761762
Thanks very much
Motaz
www.geocities.com/motaz1
0
 
LVL 5

Author Comment

by:Gwena
ID: 2761773
Nice web site Motaz

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

...Gwen..
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2761786
I also visit your homepage, but is the EasyIP only get the local computer IP address?
0
 
LVL 5

Author Comment

by:Gwena
ID: 2762643
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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 61
Making delphi communicate with a c# service 16 102
FMX and jaudiotracker playing memory stream 29 77
Delphi: making a BW image transparent 10 35
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now