Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Problem with inheritance DiagramLink (Read 1941 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Problem with inheritance DiagramLink
Aug 12th, 2011 at 7:15am
Print Post  
Hello. I have the class TPDEDiagramLink: DiagramLink.
An in this class I have some constructors:
Code
Select All
        public TPDEDiagramLink(Diagram a_ParentDiagram) : base(a_ParentDiagram)
        {
            Init();
        }
        public TPDEDiagramLink(Diagram parent, DiagramNode origin, DiagramNode destination) :
            base(parent, origin, destination)
        {
            Init();
        }
        public TPDEDiagramLink(Diagram parent, DiagramNode origin, Point destination) :
            base(parent, origin, destination)
        {
            Init();
        }
        public TPDEDiagramLink(Diagram parent, Point src, DiagramNode dest) :
            base(parent, src, dest)
        {
            Init();
        }
        public TPDEDiagramLink(Diagram parent, Point src, Point dest) :
            base(parent, src, dest)
        {
            Init();
        }
 


Also I override the method Clone:
Code
Select All
public override DiagramItem Clone(bool clipboard)
        {
            //TPDEDiagramLink link = base.Clone(clipboard) as TPDEDiagramLink;
            object obj = base.Clone(clipboard);
            if (obj is TPDEDiagramLink)
            {
                TPDEDiagramLink link = obj as TPDEDiagramLink;
                link.DescriptionRu = DescriptionRu;
                link.DescriptionEn = DescriptionEn;
                //link.ImageHLink = ImageHLink;
                //link.ImageData.Flush();
                //ImageData.CopyTo(link.ImageData);
                return link;
            }
            return obj as DiagramItem;
        }
 


And when I try to copy link into Clipboard I go to Clone. But base.Clone(clipboard); return me the DiagramLink object, not the TPDEDiagramLink object. In case with a ShapeNode after base.Clone(true) I go to the copy constructor. What I need to do with links?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Problem with inheritance DiagramLink
Reply #1 - Aug 12th, 2011 at 7:41am
Print Post  
I looked at the code and that's indeed how cloning is implemented - it creates an object through the copy constructor for all items except links. DiagramLink.Clone always instantiates DiagramLink objects.

You can work around this by not calling base.Clone and instead instantiate a link of your custom class directly:

Code
Select All
public override DiagramItem Clone(bool clipboard)
{
      TPDEDiagramLink clone = new TPDEDiagramLink(this, Origin, Destination);
      // ...
} 


You will need to add an additional constructor though - which invokes the base' class copy constructor: DiagramLink(DiagramLink, DiagramNode, DiagramNode).

I hope this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Problem with inheritance DiagramLink
Reply #2 - Aug 12th, 2011 at 7:57am
Print Post  
Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint