Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy, Paste, etc... 1

Status
Not open for further replies.

XNOR

Programmer
Nov 15, 2001
17
US
Hi, i'd like to use the ClipBoard, but what do i do when i have a large number of Edit boxes?

Am i left to check each one for Focused() or is there a function that can tell me what component is focused? Even if i were to find out which item was Focused(), how would i call the Object(in this case Edit) and use it in CutToClipBoard for example?
 
Your edit boxes have some methods that will help. For example,
Code:
EditBox1->Focused
will return true if EditBox1 has focus. Also
Code:
EditBox1->SetFocus();
will set the focus to EditBox1.

If you do
Code:
EditBox1->SelectAll();
EditBox1->CopyToClipboard;
everything in EditBox1 will be copied to the clipboard. You also have CutToClipboard and PasteFromClipboard methods.

Putting it all together:
Code:
if (EditBox1->Focused())
{
    EditBox1->SelectAll(); // get everything
    EditBox1->CutToClipboard; // CUT it to clipboard
    
    EditBox2->SetFocus(); // focus on next edit box
    EditBox2->PastFromClipboard; // PASTE from clipboard
}
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
What I have done in the past to determine focus is overloaded the OnFocus and the function that happens when it loses focus.. i forget the name atm. In the private data section I have an enumerated list and a type of that list to switch on. I hope that helps.

Matt
 
James, i understand how to check the Focus, copy and paste, its just that i have over 2 dozen edit boxes and that number will probably tripple by the time im done with this program.

The idea is that when i go up to my Edit menu and select copy, i want the selected text from any of the numerous EditBoxes set to the ClipBoard.

I suppose its obvious that i will have to indivdually check each EditBox by name for focus, and somehow get that selected text copied.

But what i was checking if anyone knew if there were maybe a list or Function that returns the name of the Object (such as EditBox1) so i can use it to perform the ClipBoard action. ie:
__fastcall Form1::Copy1Click(){
[something] focusCheck() //something like this
{if(Edit1->Focused()) //checks Edit1
return "Edit1"; //returns the name of
if(Edit2->Focused()) //Focused item
return "Edit2";
}

[something] = focusCheck();
[something]->CopyToClipBoard();
}

[something] represents maybe a variable like a String ... heh, or maybe it represents my stupidity in this whole matter.
Matt, i think your on the right track, i just dont think i understood what you were saying.

Any ideas you ppl have are welcome, thanks much.
 
Umm, I might have missed something early n the conversation but cut copy and paste dont need any help from the clipboard
to work (unless your trying to copy a lot of these edits at once?) The only time I've ever had to code anything for these functions has been if I was using a DBGrid ( I think it's would be required for images as well?? but not edit boxes ) I don't even have a reference to the clipboard in my current DB application and I can cut copy and paste easily. So... what did I miss that's making your life miserable?? Maybe I can help too..
 
Maladon,
[tab]As far as I can tell, the main problem is how to easily tell which object has focus. I know there is a way but I haven't had time to find it. Any ideas?
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
When i mentioned that i wanted to use the ClipBoard, i meant copy, cut and paste. Those three actually use it, i was making a generalization.

Anyway, i have a month before i will be compiling a final draft and would like as much to work in this program as possible before it goes out.

If anyone gets any thoughts about what like James just described, ill be keeping an eye open here, thanks all ;)

XNOR
 
I think I found a way but the problem is that it is written in Delphi (Pascal). Go to and look for article #26842 . It has been so long since I've even looked at Pascal that I can't remember how to change it to C++. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
ok, sorry, i looked but i have no clue how to navigate that community. much less search for that thread :-/




 
Well, while looking through one of my C++ books (Teach yourself C++ Builder in 21 days) i cam across the hint feature. When you want a long hint on the status bar, you have to add some specific things.

One of those that caught my eye was Application->OnHint = &OnHint; Where &OnHint is the Function that you(the programmer) creates. I think this could be used the same way with Copy for example, where OnHint represents the Copy function. then Application->Copy1Click = &OnCopy; might be how its written. that last line goes into the constructor i suppose.

Ive just come across this and am trying to resolve it. If this is on the right track, let me know.
 
I'm not familiar with the book but that sounds about right. I'll check around.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
For something closer to what im looking for... here is an example of something thats close to working:

String EditName;

an event for any editbox
OnEnter(Tobject *Sender)
{
EditName = ((TEdit*) Sender)->Name;
}

CopyClick()
{
EditName->CopyToClipboard();
}

Of course this wont work because the pointer to copytoclipboard would be looking for a property of a String. I recall seeing a way to pass/handle the name of an object...

any ideas anyone?

(i could replace 'Name' with 'Tag' as i would set all the edit boxes to incremental numbers, but i cant figure what i would do with this.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top