?
Solved

Copy & Paste in a TreeView ?

Posted on 2001-09-02
16
Medium Priority
?
1,068 Views
Last Modified: 2010-04-06
Has anybody an example how to realize
copy & paste in a TTreeView?
Multiselect = false but the function should also copy
the children of a node.

Thanks

tas
0
Comment
Question by:Tasomia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +2
16 Comments
 
LVL 3

Expert Comment

by:smurff
ID: 6448899
listening
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6449040
standard TreeView not support copy/paste tree nodes.

But you can write component with the feature.
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6449188
But how ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6450573
if you would raise the points,
then i would post a sample :-))
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6450686
Ok, now you get 130 points!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6450884
hu, well ok,
tell me which delphi-version u use
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6451062
Example:

  TCPTreeView = class(TTreeView)
  private
   procedure WMCopy(var Msg : TMessage); message WM_COPY;
   procedure WMPaste(var Msg : TMessage); message WM_PASTE;
  protected
   procedure AddNodes(ATree : TTreeView; ASrc, ADst: TTreeNode);
  public
   procedure DoCopy;
   procedure DoPaste;
  End;

------------------------------

procedure TCPTreeView.DoCopy;
begin
 Perform(WM_COPY, 0, 0);
end;

procedure TCPTreeView.DoPaste;
begin
 Perform(WM_PASTE, 0, 0);
end;


procedure TCPTreeView.AddNodes(ATree : TTreeView; ASrc, ADst : TTreeNode);
Var
 NextSrc, NextDst : TTreeNode;
Begin
 NextDst := ATree.Items.AddChild(ADst, '');
 NextDst.Assign(ASrc);

 NextSrc := ASrc.GetFirstChild;
 while Assigned(NextSrc) Do Begin
  AddNodes(ATree, NextSrc, NextDst);
  NextSrc := ASrc.GetNextChild(NextSrc);
 End;
End;

procedure TCPTreeView.WMCopy(var Msg: TMessage);
Var
 T : TTreeView;
begin
 If not Assigned(Selected) Then Exit;

 T := TTreeView.Create(nil);
 Try
  T.Visible := False;
  T.Parent := Self;
  AddNodes(T, Selected, nil);
  ClipBoard.SetComponent(T);
 finally
  T.Free;
 end;
end;

procedure TCPTreeView.WMPaste(var Msg: TMessage);
Var
 A     : TComponent;
 T     : TTreeView;
begin
 Try
  A := ClipBoard.GetComponent(Self, Self);// as TCPTreeView;
  T := A as TTreeView;
  AddNodes(Self, T.Items[0], Selected);
 finally
  T.Free;
 end;
end;


Regards.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6451070
you should add some code to keyboard handler to check for ^C/^V combination.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6451102
seems someone had waited too

good work, slavak :-)
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6451572
Hi Slavak,
Thanks for your great code!

I had to add
RegisterClasses([TTreeView]);
in order to get it work.


Now as it works for the standard TTreeView
I wanted it to work with TTreeNT.
I adapted the Code but when I run DoPaste I get an error
"the index of the list exceeds the maximum (0).

error raises here:  

function TTreeNodeList.Get(Index: Integer): TTreeNTNode;
begin
if (Index < 0) or (Index >= FCount) then
  {$ifdef DFS_COMPILER_3_UP}
    Error(SListIndexError, Index);
...


Does anybody have an idea why ?

tas

BTW: Slavak, the points are yours but I would be glad if somebody could help me with the TTreeNT problem.
0
 
LVL 3

Accepted Solution

by:
Slavak earned 390 total points
ID: 6452351
From WM_PASTE function: AddNodes(Self, T.Items[0], Selected);
 
when T (selection) is empty Index = 0 and FCount = 0, so you need check it.
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6454671
I still can't get it work. The selection is not empty!
What's wrong ?
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6454695
I still can't get it work. The selection is not empty!
What's wrong ?
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6456101
I'm not using TreeNT component and cannot do it myself, but it should be simple debugging check.
Place breakpoint in the function, and you will see Index value that make a problem.
0
 
LVL 2

Author Comment

by:Tasomia
ID: 6466839
The problem is, that after

T := A as TMYTreeNT; // My TreeNT Component


T.Items.Count is always = 0


0
 
LVL 17

Expert Comment

by:geobul
ID: 9290020
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept Slavak's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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