Solved

Copy/paste items in TOutline from the same TOutline

Posted on 1997-12-08
10
515 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 250 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
Industry Leaders: 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

Technology Partners: 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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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