Deleting LinkPoints

My app allows the user to add LinkPoints to a DiagramBlock, which works fine. But I would like to be able to delete unused LinkPoints to clean things up. So, the first question is: what is the correct method to delete a LinkPoint? There seem to be only 2 options, Free and Release. These sort of work, but cause problems. Is there a preference or is some other method better?

Q2: I am using a loop to check each LinkPoint on the Block and if it's not attached to anything, delete it:

for i  := ThisBlock.LinkPoints.Count-1  downto 0 do
    if ThisBlock.LinkPoints[i].AnchoredCount = 0 then

But, depending on the sequence of used and unused LinkPoints, this may not delete all the unused LinkPoints and some of the used LinkPoints become disconnected from the lines that were anchored to them, moving the line no longer moves the anchored line end (though they still show the line as anchored). I presume that some parameters of the LinkPoints higher in the list are getting reset, but others are not.
At the moment I am just setting the unused LinkPoints visible to False, which works fine, but it seems a very inelegant method.
Is there something I am missing or a better way to do this sort of thing?

You should use Free, and in theory it should work fine. For us to know exactly what is going on, it would be easier if you could send us a sample project reproducing the exact issue you are having.

Hi Wagner,
I have made a small demo to show what I mean. It's just the Getting Links demo with some extra buttons, they should be self explanatory.
clear (1.6 MB)

I'm sorry, I don't see any extra buttons and I don't know what to do with the demo. It works just fine for what it was originally intended to do.

Sorry, that's what comes of trying to program while half asleep after a concert that finished at 3 AM :sleeping:
I think this one should work. Just click Create Blocks & Links then Free Unused Links then move the bottom block to see the broken links.
getting (1.6 MB)

Everything works fine here. I clicked the button to create the blocks, then the button to free the blocks. No errors.
I had to remove 3rd party units (MadExcept) to be able to compile the project.

It all looks OK until you select / move the block, then you see that some of the links are broken or mis-assigned.

That's because the link points anchors are defined by index. When you destroy a link point, the index of existing link points change and thus the anchors indexes are pointing to different link points.

You have to process that in order to keep the same link points references. Or simply hide the other link points, as you were doing. That is actually a better and easier solution.

OK, thanks. I thought it would be something like that but just wanted to confirm. Hiding them does work but it's not very elegant.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.