473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About reading from Clipboard

Hello!!

I'm reading a book and there is something that I have found that may me
unnessessary.

It's a method called ReadClipboard listed below.
It read an object from the Clipboard and return it if it's valid RTF format.
It makes three checks which are:
1. Get whatever's in the clipboard.
2. Get the data out, but make sure that's it RTF data
3. OK, we got something; make absolutely sure that it's a string

Now to my question.
When the code make this second check that the object is in RTF format
is it then nessessary to make the third check. I mean but I'm not sure that
if it's in
RTF format it's also a string.
If this is true then the third check can be removed.

So will the code still be correct if the third check is removed?

private string ReadClipboard()
{
// get whatever's on the clipboard
IDataObject data = Clipboard.GetDataObject();
if (data == null)
{
return null;
}

// get the data out, but make sure that's it RTF data
object o = data.GetData(DataFormats.Rtf, true);
if (o == null)
{
return null;
}

// OK, we got something; make absolutely sure that it's a string
if ((o is string) == false)
{
return null;
}

// that's it - we got something
return (string)o;
}

//Tony


Apr 29 '06 #1
0 1190

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: xyz | last post by:
I have a menu item to handle clipboard actions (cut, copy, paste). When I paste text that I copied from a Hungarian web page, the display looks normal on my RichTextBox, but the text retrieved from...
0
by: Edward | last post by:
westmj@hotmail.com (Michael) wrote in message news:<aff51963.0310132247.1a6f5efd@posting.google.com>... > I just spent two hours trying to work out why my procedure wouldn't > allow me to set the...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
3
by: Phil Endecott | last post by:
Dear All, I'm trying to read the content of the clipboard in a cross-browser way. Google will find various scripts such as this one: ...
0
by: jen | last post by:
this works fine it i operate on one .doc file; however, if i process multiple files, i get the following error: Requested Clipboard operation did not succeed. i suspect i need to clear my...
7
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
1
by: Figmo | last post by:
Wow.....this is darned odd.... I have an app that integrates with other applications. It registers a global hotkey with Windows. When the hotkey executes it sends a CTRL-C to the active...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.