TOutline:  move an item to a different level

Q:  How do I move an outline item to a different level?   I'm trying to call

OutLine1.Items[i].ChangeLevelBy(-1)

and I get the error 'invalid outline index'.

A: The work around is to use the TOutLineNode method called MoveTo. The example below will move the currently select OutLine node up and down on the Button Click Events.
 

Gary Campbell/Tim Roth
Borland Technical Support
 

unit Uoutline;

interface

uses
  SysUtils, Forms, Dialogs, StdCtrls, Outline, Grids, Controls, Classes;

type
  TForm1 = class(TForm)
    Outline1: TOutline;
    ButtonUp: TButton;
    ButtonDown: TButton;
    procedure ButtonUpClick(Sender: TObject);
    procedure ButtonDownClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ButtonUpClick(Sender: TObject);
begin
  with OutLine1.Items[OutLine1.SelectedItem] do begin
    { Make sure your not already at the top }
    if Level > 1 then
      { This code is very similar to what ChangeLevelBy(-1) should do }
      MoveTo(Parent.Index,oaAdd);
  end;
end;

procedure TForm1.ButtonDownClick(Sender: TObject);
begin
  with OutLine1.Items[OutLine1.SelectedItem] do begin
    { Make sure you there is a previous child to be a child of }
    if Parent.GetPrevChild(Index) <> -1 then
      ChangeLevelBy(1);
  end;
end;
 

end.