How to traverse all liveblocks of workflow diagram

How to traverse all liveblocks of workflow diagram?

  Assuming wkins is a workflowinstance:
1,wkins.Diagram.Liveds[0] is null,I can not access the first node of the diagram,why?
2,I use wkins.Diagram.LastNode and wkins.Diagram.NextNode,but both point to the same node,it is
the current node(TCustomLiveBlock).



You must interact through property BlockCount, Blocks, LinkCount and Links (to get blocks and lines available) and check Blocks[c].Anchoreds[].DControl and/or Links[c].LinkPoints[].Anchor to check what lines are connected to what blocks.

The LastNode, NextNode, etc., are not available since they are only changed when workflow is being executed.

Can you show me, how to get next block of current task?

What (or maybe better, why) you want to do, exactly? Because strictly speaking, there is no "next block of current task". In a task you have several final status and each of them usually flow to a different block. So the next block of a task is only defined after the task is finished and the task status is computed.

I want to read internal status (not completion status) of task after selection correct link and

before save the task.

Sorry, but I didn't understand. What do you mean by internal status, and what you mean by "after selection correct link"?

Each block has its own list status and a list of links
When I select the specific link coming out of the block I want to read a list of statuses in the next block

Here is a snippet of code from the TMS Diagram Studio "getting links" demo, which shows all incoming and ongoing links of a specific block, and what other blocks are connected to it. With this code you can check the next blocks (in diagram), check if they are a task block and then get the status list from it:

procedure TForm1.CheckBlockLinks(ABlock: TCustomDiagramBlock);

  procedure CheckLink(ALink: TCustomDiagramLine);
    ConnectStr: string;
    ConnectedControl: TDiagramControl;
    ConnectedName: string;
    {A link has two connection points. We must find out which point has
     the block we are analysing, and which point has the other connected block
     (if any)}
    if ALink.SourceLinkPoint.Anchor = ABlock then
      ConnectedControl := ALink.TargetLinkPoint.Anchor;
      ConnectStr := '-->';
    end else
      ConnectedControl := ALink.SourceLinkPoint.Anchor;
      ConnectStr := '<--';

    if ConnectedControl = nil then
      ConnectedName := 'none'
      ConnectedName := ConnectedControl.Name;
    Memo1.Lines.Add(Format('%s (%s) %s %s',
      [ConnectStr, ALink.Name, ConnectStr, ConnectedName]));

  c: integer;
  d: integer;
  Memo1.Lines.Add(Format('%s links:',[ABlock.Name]));

  {Iterate through each link point (connection point) available in block}
  for c := 0 to ABlock.LinkPoints.Count - 1 do
    {For each link point, iterate through the controls which are anchored to it}
    for d := 0 to ABlock.LinkPoints[c].AnchoredCount - 1 do
      {If the anchored control is a line, then analise it.
       * for now, only lines can be anchored to a link point, so this
         test is not needed. But in a future version other types of
         controls can be anchored to a link point, so do the test already}
      if ABlock.LinkPoints[c].Anchoreds[d].DControl is TCustomDiagramLine then


I can't run the code;

TCustomDiagramBlock, TCustomDiagramLine, TDiagramControl  : Undeclared identifier
(what to add to uses clause)?

And how to call the procedure? How to get a current block of taskinstance?

Those are declared in atDiagram unit.

You don't have the current block of a task instance. The task is separated from workflow engine. The engine knows it's waiting for a task, but the task doesn't know what block it's related to.
You mentioned you were using NextNode property, can't you use that?

I've added atDiagram  to uses clause but TCustomDiagramBlock and TCustomDiagramLine still are Undeclared. 

But I found TCustomWorkflowBlock class. Can I use it?

You can use TCustomWorkflowBlock, yes, since it's the base class for all blocks in a workflow diagram. But TCustomDiagramBlock and TCustomDiagramLine are definitely declared in unit atDiagram, something is wrong...

workflowinstance.Diagram.NextNode return TCustomLiveBlock, so I changed TCustomDiagramBlock to TCustomLiveBlock and added LiveDiagram to uses clause and the code compiled succesfully.
But, I still don't know how to call CheckBlockLinks procedure, because I don't know how to get taskinstance current block.

As I said, there is no such current block for task instance. All you have is current block for the workflow instance itself, which is NextNode (if the task isn't finished, NextNode points to the task block itself). I still don't understand what exactly you want to achieve.

My blocks have few statuses (to note, to edit, to reply etc) (not completion statuses)

I want to change current block and then set status

Ok but why do you need that? We have never heard of such need, probably because users used a different solution for a similar problem. Why do you need to change status of a task definition when the task instance is not created yet? Are you aware that to change the status of a task instance you just modify the task instance itself?

Now my program works in this way.
I choose completion status and The Workflow go to the next block. Then I again change not completion status and Workflow stay on current block. And it works fine.
But if I accidentally choose wrong completion status I can't back to previous block
so I want to gather all the informations (current status and status at the next block) and then perform all operations.

What "operations"? How are you going to prevent that a user chooses the wrong completion status accidentally? 

Anyway, that's the workflow operation. You can always create a new status in the next block called "rollback" and then when that status is chosen, your workflow goes back to the previous block to recreate the original task. 
Unfortunately, my client doesn't likes your solution with extra back arrow.
He wants a Cancel button AFTER get all informations about next diagram block and BEFORE change status of a task;