Solved

Help with copy and paste.

Posted on 2001-06-14
11
184 Views
Last Modified: 2010-04-06
0
Comment
Question by:pucko
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6190488
What do you want exactly???
0
 
LVL 3

Expert Comment

by:MarcG
ID: 6190493
What do you need ?  for copy press CTRL + C and for paste CTRL + V.
??????????
0
 
LVL 3

Expert Comment

by:MarcG
ID: 6190510
What do you need ?  for copy press CTRL + C and for paste CTRL + V.
??????????
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6190512
See this article maybe it what u r looking for

TCLIPBOARD.CUT-COPY-PASTE
http://delphi.about.com/compute/delphi/library/weekly/aa092199.htm

also this
Listening to the Clipboard
http://delphi.about.com/compute/delphi/library/weekly/aa110700a.htm

Best regards
Mohammed Nasman
0
 
LVL 3

Expert Comment

by:alzv
ID: 6190513
If you want to copy and paste something from your code, look at Clipboard object...
0
 
LVL 3

Expert Comment

by:MarcG
ID: 6190514
sorry for sending twice
0
 
LVL 1

Author Comment

by:pucko
ID: 6190531
Wtf... something went wrong with my submittion.
I had a hudreds of lines here.


I have A window (Say q_window)that I can open several instances of.
In the Window I have a treeView looking like this:


mother-node--|
             |
             |BlocksNode
                       |
                       |
                       |Block1
                       |     |
                       |     |
                       |     |-BlockItem1
                       |     |-BlockItem2
                       |
                       |Block2
                             |
                             |-BlockItem1
                             |-BlockItem2

It can contains dynamicly number of blocks and each block can contain dynamic number of BlockItems.


So I want to copy a whole Block to another q_window under The Blocks Node.

Each Block Has A Block_no so I have to go through The Target TreeView to find out the highest block_no in that Tree and set the BlockNo to that number+1 when I paste it.
The same for each BlockItem. (the BlockItem.block_no refers to which block it is related to.


I tried this: (so you can se what I try to do):



procedure TQuoteForm.Copy1Click(Sender: TObject);
begin
  if T
  Clipboard.SetComponent(TreeView1);
  RegisterClasses([TTreeview]);
end;

procedure TQuoteForm.Paste2Click(Sender: TObject);
var
  ThisComponent : TComponent;
  ThisTreeView : TTreeView;
  TmpBlockNode : TTreeNode;
  BlocksNode : TTreeNode;
  TreeNode : TTreeNode;
  no, ix : integer;
  ThisBlock : TBlock;
  tmpNode : TTreeNode;
  ThisBlockItem : TBlockITem;
begin
  if Clipboard.HasFormat(CF_COMPONENT) then
  begin
    ThisComponent:= Clipboard.GetComponent(self, self);
    ThisTreeView:= TTreeView(ThisComponent);
    ThisTreeView.Visible:= False;
    TmpBlockNode := TTreeView(ThisComponent).Selected;
    BlocksNode:= FindNode(TreeView1.Items[0],'TBlocksNode');
    no:= 0 ;
    for ix:= 0 to BlocksNode.Count-1 do
    begin
      if no < TBlock(BlocksNode.Item[ix].Data).block_no then
        no:= TBlock(BlocksNode.Item[ix].Data).block_no
    end;
    Inc(no);
    TreeView1.Items.BeginUpdate;
    ThisBlock := TBlock(TmpBlockNode.Data);
    with ThisBlock do
    begin
      quote_no:= Current_quote.quote_no;
      version:= Current_quote.version;
      alternate:= Current_quote.alternate;
      block_no:= no;
    end;
    TreeNode:= TreeView1.Items.AddChild(BlocksNode, RemoveTAB(RemoveCRLF(ThisBlock.header)));
    TreeNode.Data:= ThisBlock;
    TreeNode.ImageIndex:= tiFolder;
    BlocksNode.Expand(False);
    for ix := 0 to TmpBlockNode.Count-1 do
    begin
      ThisBlockItem:=TBlockITem(TmpBLockNode[ix].Data);
      ThisBlockItem.quote_no:=Current_quote.quote_no;
      ThisBlockItem.version:=Current_quote.version;
      ThisBlockITem.alternate:=Current_quote.alternate;
      ThisBlockItem.block_no:=no;
      tmpNode:= TreeView1.Items.AddChild(TreeNode, FormatArtNo(ThisBlockItem.art_no));
      tmpNode.Data:= ThisBlockItem;
      tmpNode.ImageIndex:= GetTreeImageByClass(ThisBlockItem.class1);
    end;
    TreeView1.Items.EndUpdate;
    UpdateListView;
    CalcBlockItemArrange;
    QuoteModified(True);
    TTreeView(ThisComponent).Free;
  end;
end;


0
 
LVL 3

Accepted Solution

by:
MarcG earned 300 total points
ID: 6192810
what's wrong with your code ? didn't try it ... but one question, why are you using clipboard for this ? here's how i would try it :
you have a main window, and in this main window you create the q_windows. so all q-wins can access the main windows... i would make a public variable (maybe record) that when copying a block gets the source window and the block nr to copy. when pasting a block to another q_win this win gets the info from the main window. then you check the numbers and create new nodes with the right numbers in the target treeview.  
only the block nr is written in the public record, for creating the new nodes the infos are read directly from the source treeview.
0
 
LVL 1

Author Comment

by:pucko
ID: 6194020
The problem with my code is that when I do the paste thing
it still tries to use the TreeView that I copied.

SO if I Have 3 Blocks in the one that I try to copy from and none in the one I try to paste it into,
 this code:

BlocksNode:= FindNode(TreeView1.Items[0],'TBlocksNode');
   no:= 0 ;
   for ix:= 0 to BlocksNode.Count-1 do
   begin
     if no < TBlock(BlocksNode.Item[ix].Data).block_no then
       no:= TBlock(BlocksNode.Item[ix].Data).block_no
   end;
   Inc(no);

Gives me 3 blocks.

So It still thinks that I'm working with the treeView that I copied and not the one in the new window.

The second problem is that:

TmpBlockNode := TTreeView(ThisComponent).Selected;

Always becomes the Mother Node and not the one that I selected when I did copy.

I prefere to use the Clipboard for this but I don't know how to do. There should be some way to do this I think.

If I use your Idea MarcG, I cant close the window I copied from before I have paste it into the other, Right?

0
 
LVL 3

Expert Comment

by:MarcG
ID: 6196658
yes, with that you are right ...or you have to copy the data needed in some temp variables then you can close the window and still copy the files.
make a record with the data needed for one node and then make a dynamic array of this record. when copying first put all the data there and when pasting read it from there.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9285972
pucko,
No comment has been added lately (811 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to MarcG http:#6196658

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

DragonSlayer
EE Cleanup Volunteer
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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