Displaying a Hierarchy in a Level Graph

This example, a little simpler than that supplied with Lazarus, has on the form only a TLvlGraphControl (from the LazControls component tab). It displays the same data as the TreeView on the preceding page. The display is customisable as indicated in the Lazarus 1.2 release notes and the component offers great scope for experimentation.

Screenshot of program in action

Screenshot of program in action

The screenshot is taken with the mouse pointer over the TComponent node.

Pascal Code of Form

unit uLevelGraphDemo;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LvlGraphCtrl, Forms, Controls, Graphics, Dialogs;

type
  TForm1 = class(TForm)
    LvlGraphControl1: TLvlGraphControl;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  with LvlGraphControl1 do
    begin
      Graph.GetEdge('TObject', 'TPersistent', true);
      Graph.GetEdge('TPersistent', 'TComponent', true);
      Graph.GetEdge('TComponent', 'TLCLComponent', true);
      Graph.GetEdge('TLCLComponent', 'TControl', true);
      Graph.GetEdge('TControl', 'TWinControl', true);
      Graph.GetEdge('TWinControl', 'TCustomControl', true);
      Graph.GetEdge('TCustomControl', 'TCustomTreeView', true);
      Graph.GetEdge('TCustomTreeView', 'TTreeView', true);
      Graph.GetEdge('TWinControl', 'TCustomEdit', true);
      Graph.GetEdge('TCustomEdit', 'TEdit', true);
      Graph.GetEdge('TCustomEdit', 'TCustomMemo', true);
      Graph.GetEdge('TCustomMemo', 'TMemo', true);
      Graph.GetEdge('TWinControl', 'TCustomComboBox', true);
      Graph.GetEdge('TCustomComboBox', 'TComboBox', true);
      Graph.GetEdge('TWinControl', 'TButtonControl', true);
      Graph.GetEdge('TButtonControl', 'TCustomButton', true);
      Graph.GetEdge('TCustomButton', 'TButton', true);
      Graph.GetEdge('TWinControl', 'TCustomListBox', true);
      Graph.GetEdge('TCustomListBox', 'ListBox', true);
      Graph.GetEdge('TControl', 'TGraphicControl', true);
      Graph.GetEdge('TGraphicControl', 'TCustomLabel', true);
      Graph.GetEdge('TCustomLabel', 'TLabel', true);
      NodeStyle.Shape := lgnsEllipse;
      NodeStyle.Width := 15;
      NodeStyle.GapTop := 8;
      NodeStyle.CaptionPosition := lgncBottom;
      Font.Size:= 11;
    end;
end;

end.                               

Programming - a skill for life!

How to use a TTreeView and a TLvlGraphControl in Lazarus