Solved

Help with copy and paste.

Posted on 2001-06-14
11
185 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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