Solved

Copy/paste items in TOutline from the same TOutline

Posted on 1997-12-08
10
505 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
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!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 355
Delphi 2 77
PHP preg_replace code convert to Delphi 14 80
Firemonkey how to swip panel with finger tap 1 19
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…

762 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