Solved

Help with copy and paste.

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

Expert Comment

by:mnasman
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
 
LVL 22

Expert Comment

by:mnasman
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

21 Experts available now in Live!

Get 1:1 Help Now