OnAcceptLink usage

I think I'm missing something about the OnAcceptLink event usage.

I would like to restrict which blocks can be connected, but I didn't figured out how to do it.
I tried checking the Anchor1.Anchor property but is always nil, i.e.

procedure TLogicEditor.DiagramEditorAcceptLink(Sender: TObject;
  ALink: TCustomDiagramLine; Anchor1, Anchor2: TLinkPoint;
  var Accept: Boolean);
var
  s:string;

begin
  if (Anchor1<>nil) and (Anchor1.Anchor<>nil) then
    s:=Format('source class %s',[Anchor1.Anchor.ClassName])
  else
    s:='';
  if (Anchor2<>nil) and (Anchor2.Anchor<>nil) then
    s:=s+Format(' target class %s',[Anchor2.Anchor.ClassName]);
  if s<>'' then
    OutputDebugString(PAnsiChar(s));
end;

Nothing is ever output on the debug console, which means that Anchor1.Anchor and Anchor2.Anchor are always both nil.

Hi,

Perhaps a different approach which will solve your problem ( Not using the on accept link events ):

Each diagram block has 10 Restrictions which can be set ( they should be listed under the components properties ), such as crNoMove, crNoLink etc.

Setting the crNoLink restriction of a block to true will prevent linking of that block.

It seems the 10 restrictions are stored in a 10-bit buffer ( I might be wrong ), hence you can't simply set one to true or false. You have to set the whole buffer at once.

eg. ( sorry this is in c++, but should give a good idea ):

Your DiagramBlock pointer(handle):  pBlock
Setting the whole buffer

pBlock->Restrictions = (TControlRestrictions)( <some Hex-value> );         ( some Hex-value such as 0x12D - that is cast to TControlRestrictions. 0X200 if you just want to set the crNoLink restriction to true and keep the rest on false ).

Perhaps a single restriction can also be set true by converting the TControlRestrictions of a block to Hex, then logic-OR'ing the relevant bit of that Hex-value with 1, and then using the resulting Hex-value as shown above. ( haven't tested this yet, but it should work ).

Hope this is applicable to your problem.
Regards



Or if the blocks are not being inserted dynamically and you have a design view you can just check the Restrictions:crNoLink checkbox in the block's properties.

Anchor1 and Anchor2 parameters are link points of the block, not the line. Thus, Anchor1.Anchor property will always be nil, because such link points are not connected to any other control. The property you are looking for is Anchor1.DControl, which indicates to which diagram control (block) that link point belongs to.