Search
Delphi Quick Start

This section describes how to use FlowChartX with Borland Delphi:

Creating new project & adding the control to it.

Create new project choosing "File -> New" from the menu and select "Application" from New tab in New Items dialog. Finally press OK button. Back to main menu select "Component -> Import ActiveX Control". In "Import ActiveX" dialog choose FlowChart Type Library and click "Create Unit" button. The file FLOWCHARTLib_TLB.pas is created into your Import directory. By default your Import directory is located in the Delphi directory. To install the newly imported component, you have to compile it into a package. This is done by selecting "Components -> Install Component..." from the menu. Afterwards click "Into new package" tab page, type the name for the package file into "Package file name" edit box and click OK. FlowChartX is installed in the "ActiveX" section of the "Component palette". If the palette is not present you can show it from "View -> Toolbars -> Component palette".

Customizing the application form.

In addition to the FlowChartX you can add some UI components to carry out additional program functionality. In our example two buttons for easier interaction with the program are inserted - 'Modify' and 'DestBoxes'.

Working with the object collections.

Now, with buttons ready, add some functionality to them by creating their event handlers. Do it by double-clicking each of the buttons. ModifyClick and DestBoxesClick methods should appear in your form class, considering the buttons' names are 'Modify' and 'DestBox' respectively. First button modifies all selected boxes appearance, while second one selects all child boxes for active selected box in the current selection (e.g. all boxes pointed by outgoing arrows). Following code snippet illustrates that:

Delphi  Copy Code

procedure TForm1.ModifyClick(Sender: TObject);
var

    box: IBoxItem;
    boxes: IBoxes;
    iBoxes: Integer;

begin

    // Iterate throug all selected boxes
    // and change their appearance.
    boxes := FlowChart1.SelectedBoxes;

    for iBoxes := 0 to boxes.Get_count() - 1 do
    begin

        box := boxes.Get_Item(iBoxes);
        box.Set_PenWidth(3);
        box.Set_FillColor($FF00FF);
        box.Set_FrameColor($FF0000);

    end;

end;

procedure TForm1.DestBoxesClick(Sender: TObject);
var

    boxSelected: IBoxItem;
    arrowsOut: IArrows;
    arrow: IArrowItem;
    iArrow: Integer;

begin

    // Get the current active selected box.
    // If the selected box is not present, then
    // notify the user.
    boxSelected := FlowChart1.ActiveBox;

    if boxSelected = nil then
        Application.MessageBox('Select a box first!', 'Form1', MB_OK)
    else
    begin

        // Clear FlowChart selection first.
        FlowChart1.ClearSelection;

        // Then iterate through all ougoing arrows,
        // get their destination boxes and add them
        // to the control selection.
        arrowsOut := boxSelected.Get_OutgoingArrows;

        for iArrow := 0 to arrowsOut.Get_count() - 1 do
        begin

            arrow := arrowsOut.Get_Item(iArrow);
            FlowChart1.AddToSelection(arrow.Get_DestinationBox);

        end;

    end;

end;

Handling FlowChartX events.

Following steps illustrate specific FlowChartX events handling. In "Dialog editor" select the control then hit "Events" tab and in Object inspector window choose the events you wish to handle and add event handler methods for them. For example you can add an event handler for BoxCreated event. Name this method OnBoxCreated. In order to give this method the desired functionality a "ColorDialog" control named ColorDialog1 should be added to form layout. Click "Dialogs" tab in "Component palette", select "ColorDialog" and create one in the form. Following code snippet illustrates how to make ColorDialog1 appear:

Delphi  Copy Code

procedure TForm1.OnBoxCreated(Sender: TObject; const pBoxItem: IBoxItem);
begin

    // Display a ColorDialog here to set new color
    // to the currently created box.
    try

        ColorDialog1.Color := pBoxItem.Get_FillColor();

        if ColorDialog1.Execute then
            pBoxItem.Set_FillColor(ColorDialog1.Color);

    except

        ShowMessage('Color selection dialog failed to load');

    end;

end;