?
Solved

Copy/paste items in TOutline from the same TOutline

Posted on 1997-12-08
10
Medium Priority
?
528 Views
Last Modified: 2012-05-04
Delphi 1.0 question...

Q: Does a TOutline.CopyTo method exist, similar to TOutline.MoveTo() except that instead of moving items within the outline this method would make a mirror image of all items at the "from" level and insert it into the "destination" index point?

Since I couldn't find anything in the online help file, I would have to assume the answer is 'no'.

Next question...how can one accomplish this task?  (Hint, hint...example please).

Example (before):

  111
     aaaa
  222
     bbbb
        %%%%
     cccc
  333

Task: copy 222 and all its children and place/insert them below "aaaa" so that the result looks like:


  111
     aaaa
       222
          bbbb
             %%%%
          cccc
  222
     bbbb
        %%%%
     cccc
  333

0
Comment
Question by:Kapusta
[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
  • 3
10 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1353172
There is no Moveto in the TOutline.
Are you working with TOutline or TTreeview?
0
 

Author Comment

by:Kapusta
ID: 1353173
Ronit asked: "Are you working with TOutline or TTreeview?"


Kapusta replied: My message stated clearly "TOutline" and the title was "Title: "Copy/paste items in TOutline from the same TOutline""

0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 1000 total points
ID: 1353174
Hi

The following routine will copy outline nodes for you.  Be careful not to copy part of the tree on to one of its own branches!  I wrote this in Delphi 3, but I think it should work in Delphi 1 from looking at the Delphi 1 help file.

procedure CopyNodes(OutLine: TOutLine; FromIx, ToIx: Integer);

  procedure CopyChildNodes(var FromIx, ToIx: Integer);
  var
    ChildIx, NewNodeIx: Integer;
    Node, ChildNode: TOutlineNode;
  begin
    Node := Outline.Items[FromIx];              
    ChildIx := Node.GetFirstChild;
    while (ChildIx >= 0) do begin
      ChildNode := Outline.Items[ChildIx];
      NewNodeIx := Outline.AddChildObject(ToIx, ChildNode.Text, ChildNode.Data);
      if (FromIx > ToIx) then begin
        Inc(ChildIx);
        Inc(FromIx);
      end;
      if (Outline.Items[ChildIx].GetFirstChild >= 0) then
        CopyChildNodes(ChildIx, NewNodeIx);
      ChildIx := Node.GetNextChild(ChildIx);
    end;
  end;

var
  NewToIx: Integer;
begin
  NewToIx := Outline.AddChild(ToIx, Outline.Items[FromIx].Text);
  if (FromIx > ToIx) then
    Inc(FromIx);
  CopyChildNodes(FromIx, NewToIx);
end;

JB

P.S.  Sorry in advance about any loss of code indentation...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Kapusta
ID: 1353175
Thanks for such a great example.  The TOutline "copy/clone" code works great!
0
 

Author Comment

by:Kapusta
ID: 1353176
JimBob,

I spoke a bit too soon.  There is something wrong with the code sample that you posted.  I am finding in some instances that the newly copied items are missing several items from their original position.

For example, if you were to copy "Veterinarians" below to "Pet Grooming services", you would find that the newly copied items are lacking the 5 last items in the original group.

Try it with the example outline items below and you will see what I am talking about.


Pet grooming services
Veterinarians
      Stafford County
            Ferry Farm Animal Clinic, Ltd.
                  Dr. Larry Witter
                  371-5090
            White Oak Animal Hospital
                  Dr. Stacy L. Horner
                  374-0462
      Spotsylvania County
      City of Fredericksburg
            Princess Anne Animal Hospital
                  373-8181
                  Dr. Lee A. Gibbons


0
 

Author Comment

by:Kapusta
ID: 1353177
The indentation was lost in my last post, so let's try the example outline over again...

Pet grooming services
Veterinarians
        Stafford County
                Ferry Farm Animal Clinic, Ltd.
                        Dr. Larry Witter
                        371-5090
                White Oak Animal Hospital
                        Dr. Stacy L. Horner
                        374-0462
        Spotsylvania County
        City of Fredericksburg
                Princess Anne Animal Hospital
                        373-8181
                        Dr. Lee A. Gibbons
0
 

Author Comment

by:Kapusta
ID: 1353178
The indentation is still not correct.  How about contacting me at: 74170.3550@compuserve.com so that I can give you the file, or else try downloading:

http://www.pcshareware.com/outline.txt
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353179
Hi

I've just got back from holiday, so sorry about the delay.  I will download the file you refer to on Monday and get back to you.

JB
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353180
Hi

I'm very sorry about the delay!!!  The problem was occuring when child items had > 1 sibling under certain circumstances.  The following should fix the problem.

procedure CopyNodes(OutLine: TOutLine; FromIx, ToIx: Integer);

  procedure CopyChildNodes(var FromIx, OldFromIx, ToIx: Integer);
  var
    ChildIx, NewNodeIx: Integer;
    Node, ChildNode: TOutlineNode;
  begin
    Node := Outline.Items[FromIx];              
    ChildIx := Node.GetFirstChild;
    while (ChildIx >= 0) do begin
      ChildNode := Outline.Items[ChildIx];
      NewNodeIx := Outline.AddChildObject(ToIx, ChildNode.Text, ChildNode.Data);
      if (FromIx > ToIx) then begin
        Inc(ChildIx);
        Inc(OldFromIx);
        Inc(FromIx);
      end;
      if (Outline.Items[ChildIx].GetFirstChild >= 0) then
        CopyChildNodes(ChildIx, FromIx, NewNodeIx);
      ChildIx := Node.GetNextChild(ChildIx);
    end;
  end;

var
  NewToIx, NewFromIx: Integer;
begin
  NewToIx := Outline.AddChild(ToIx, Outline.Items[FromIx].Text);
  if (FromIx > ToIx) then
    Inc(FromIx);
  NewFromIx := FromIx;
  CopyChildNodes(FromIx, NewFromIx, NewToIx);
end;


Regards,
JB
0
 

Author Comment

by:Kapusta
ID: 1353181
Yes, your update to CopyNodes does indeed appear to have fixed the problem.  I appreciate the time you have taken to assist me.  Thanks.  :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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
Course of the Month13 days, 23 hours left to enroll

801 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