Skip to content

TTMSFNCBloxControl

Inserting objects

To insert objects in TTMSFNCBloxControl, you must:

  1. Create the object, instantiating the class of the object of choice.
  2. Set the properties you want to change
  3. Add the object to the blox collection property of the TTMSFNCBloxControl

Example:

procedure TForm1.AddBlockButtonClick(Sender: TObject);
var
 b: TTMSFNCBloxBlock;
begin
 b := TTMSFNCBloxBlock.Create;
 b.Left := 10;
 b.Top := 40;
 b.Height := 75;
 b.Width := 100;
 TMSFNCBloxControl1.Blox.Add(b);
end;
VTTMSFNCBloxControl

Removing an object

To remove an object from the TTMSFNCBloxControl, simply remove the block from the blox list.

TMSFNCBloxControl1.Blox.Remove(MyBlock);
Alternatively, you can remove the currently selected objects in the TTMSFNCBloxControl with the following code:
TMSFNCBloxControl1.Presenter.DeleteSelecteds;

Adding a line between two blocks (linking blocks)

A line start (or end) can be attached to a link point. To link two blocks, you must attach the start of a line to a block linkpoint, and attach the end of the line to another block linkpoint. Below is an example that demonstrates this.

procedure TForm1.AddLineButtonClick(Sender: TObject);
var
 l: TTMSFNCBloxLine;
begin
 l := TTMSFNCBloxLine.Create;
 l.SourceLinkPoint.AnchorLink := SomeBlock.LinkPoints[0];
 l.TargetLinkPoint.AnchorLink := AnotherBlock.LinkPoints[1];
 TMSFNCBloxControl1.Blox.Add(l);
end;

Using an picture as the block shape

If you want to use a picture as the block shape, you need to load the picture, and also set the shape to none, so the shape block is not drawn, only the picture. Example:

procedure TForm1.AddBlockButtonClick(Sender: TObject);
var
 b: TTMSFNCBloxBlock;
begin
 b := TTMSFNCBloxBlock.Create;
 b.Left := 10;
 b.Top := 40;
 b.Height := 75;
 b.Width := 100;
 b.Shape := NoShape;
 b.Picture.LoadFromFile('MyImage.png');
 TMSFNCBloxControl1.Blox.Add(b);
end;

TTMSFNCBloxControl1

Creating linkpoints in a block

To create linkpoints, the LinkPoints collection must be used.Each linkpoint is a collection item. The position of the linkpoint must be set relatively to the rect specified by the Drawer.OriginalRect property. By default, OriginalRect is (0, 0, 100, 100), making it easy to define link points positions in terms of % of block width/height. The following example, from the Flowchart blocks unit, shows how to define four link points for the block, at the top, left, right and bottom sides of the block, in the middle of each line segment.

procedure TTMSFNCBloxFlowChartBlock.UpdateLinkPoints;
begin
 LinkPoints.Clear;
 with Drawer.OriginalRect do
 begin
 LinkPoints.AddLink((Right - Left) / 2, Top, aoUp);
 LinkPoints.AddLink((Right - Left) / 2, Bottom, aoDown);

Accessing TextCells of a line object

The line objects has at least one text cell defined by default. If you want to access a text cell of a TTMSFNCBloxLine object, for example, you can use this code:

var
 t: TTMSFNCBloxTextCell;
begin
 t := LinkLine.TextCells[0];
end;

Changing category of block

Calling RegisterElement for any existing block will re-register it. So it’s possible to change the category or caption for the block. The following code moves all the blocks to the “MyBlocks” category.

TTMSFNCBloxControl2

RegisterElement(TTMSFNCBloxBlock, '', 'Simple block', 'MyBlocks');
RegisterElement(TTMSFNCBloxLine, '', 'Line', 'MyBlocks');
RegisterElement(TTMSFNCBloxTextBlock, '', 'Text block', 'MyBlocks');
RegisterElement(TTMSFNCBloxSideLine, '', 'Side line', 'MyBlocks');
TMSFNCBloxSelector1.Rebuild;

Prevent a line from being detached from a block

To prevent a line from being detached from a block, simply set the RequireConnections property to true on the line object.

MyLine1.RequiresConnections := True;

Methods

Method name Description
BeginUpdate; Blocks all visual updates. Needs to be paired with EndUpdate;
EndUpdate; Blocks all visual updates. Needs to be paired with BeginUpdate; When EndUpdate is called, the control is automatically recalculated/repainted
Load; Loads the saved state of the TTMSFNCBloxControl (saved with the Save method)
LoadFromFile(AFileName: string); Loads a diagram from a specific file
LoadFromStream(AStream: TStream); Loads a diagram from a specific stream
RegisterElements; Forces a re-register of all the supported basic and extra elements and additionally calls the OnRegisterElements event to re-register custom elements
Save; Saves the diagram
SavedBlox: string; Returns the state of the diagram as a string
SaveToFile(AFileName: string); Saves the state of the diagram to a file
SaveToImage(AFileName: string; ABloxOnly: Boolean = True; ALinkPoints: Boolean = False; ABackground: Boolean = True); Saves the diagram to an image, based on a specific series of parameters to enable disable the background, show or hide the link points and display only the blocks or also the rulers and snap grid
SaveToStream(AStream: TStream); Saves the diagram to a stream

Events

Event name Description
OnAfterBackgroundRender Event called after the background is rendered. With the Renderer.Canvas parameter you are able to add additional drawing to the blox control
OnAfterMove Event called after an element has been moved
OnAfterRender Event called after all elements are rendered
OnAfterResize Event called after an element is resized
OnBeforeRender Event called before all elements are rendered
OnElementClick Event called when a specific element is clicked
OnElementDblClick Event called when a specific element is double clicked
OnElementInsert Event called when an element is inserted
OnElementMouseDown Event called when the mouse is down on an element
OnElementMouseMove Event called when the mouse is moving over an element
OnElementMouseUp Event called when the mouse is up on an element
OnElementPainted Event called when an element is done painting
OnElementPainting Event called when an element is being painted
OnElementRemove Event called when an element is removed
OnElementResizing Event called when an element is being resized
OnElementSelect Event called when an element is selected
OnElementUnselect Event called when an element is unselected
OnModified Event called when a modification is made to the blox control
OnRegisterElements Event called when the blox control is registering all basic an extra elements and you want to register your own custom elements or you want to re-arrange existing elements in different categories
OnSelectionChange Event called when the selection is changed between elements
OnGetInplaceEditorClass Event called when the in-place text editor is created. Default this is the TTMSFNCBloxMemo.
OnSetInplaceEditorSize Event called when the in-place text editor is shown.
OnSetInplaceEditorData Event called when the in-place text editor retrieves the text from the block.
OnSetInplaceEditorElementData Event called when the in-place text editor is closed and sets the text of the block.