Skip to main content

Code Example: How to Create a Chart Symbol and Connection at Runtime

  • 3 minutes to read

This topic includes the code snippets that show how to create chart symbols and bind them with the connection in code:

uses
// Contains the TdxFlowChartObjectAdvancedShape class declaration
  ..., dxFlowChartShapes;
var
  AObj, AObj1, AObj2: TdxFcObject;
  AAdvancedShape: TdxFlowChartObjectAdvancedShape;
  AConnection: TdxFcConnection;
  I: Integer;
begin
  // Assigns the "Off Page Reference" shape from the advanced shape repository to the AAdvancedShape variable
  AAdvancedShape := dxFlowChart1.Repository.BasicFlowchartShapes.OffPageReference;
  for I := 0 to 1 do
    begin
      // Adds the advanced shape with predefined dimensions to the specified position
      AObj := dxFlowChart1.CreateObject(10, 10, 100, 50, AAdvancedShape);
      // Fills the shape's background with the silver color
      AObj.BkColor := clSilver;
      // Fills the shape's background with the gray color
      AObj.ShapeColor := clGray;
      // Sets text to display within the shape
      AObj.Text := 'Shape ' + IntToStr(I);
      // Centers text horizontally within the shape
      AObj.HorzTextPos := fchpCenter;
      // Centers text vertically within the shape
      AObj.VertTextPos := fcvpCenter;
    end;
  // Provides access to the first shape
  AObj1 := dxFlowChart1.Objects[0];
  AObj2 := dxFlowChart1.Objects[1];
  // Shifts the shape right by 150 pixels from the origin of the control's client area
  AObj2.Left := 150;
  // Shifts the shape down by 110 pixels from the origin of the control's client area
  AObj2.Top := 110;
  // Rotates the shape clockwise by 90 degrees
  AObj2.Angle := 90;
  // Attaches the connection to shapes at the specified points
  AConnection := dxFlowChart1.CreateConnection(AObj1,AObj2,2,2);
  // Sets one-pixel width for the connection line
  AConnection.PenWidth := 1;
  // Sets the dashed line for the connection
  AConnection.PenStyle := psDash;
  // Sets the vertical line that connects shapes at a right angle
  AConnection.Style := fclRectV;
  // Sets text to display within the connection
  AConnection.Text := 'Connection';
  // Fills the connection with the gray color
  AConnection.Color := clGray;
  // Assigns no shape to the connection's start arrow
  AConnection.ArrowSource.ArrowType := fcaNone;
  // Assigns the "Filled Arrow" shape to the connection's destination arrow
  AConnection.ArrowDest.ArrowType := fcaFilledArrow;
end;