Link to home
Start Free TrialLog in
Avatar of pucko
pucko

asked on

Help with copy and paste.

Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

What do you want exactly???
Avatar of MarcG
MarcG

What do you need ?  for copy press CTRL + C and for paste CTRL + V.
??????????
What do you need ?  for copy press CTRL + C and for paste CTRL + V.
??????????
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
If you want to copy and paste something from your code, look at Clipboard object...
sorry for sending twice
Avatar of pucko

ASKER

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;


ASKER CERTIFIED SOLUTION
Avatar of MarcG
MarcG

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pucko

ASKER

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?

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.
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