1
votes

The software I am working on was originally written in Delphi, and any recent additions to the software have been done in C#. I would like to derive some C# forms from base Delphi forms. I have managed to get most of it working, except when I try to open the Design view of the C# form in Visual Studio 2008 I get an error. The error message is as follows "Constructor on type'base class' not found."

I have done some searching and apparently this is due to the Delphi form not having a default constructor which takes zero arguments. The Delphi TForm class does not have a default constructor which takes zero arguments so I can't just add one to my Delphi form.

The code I have compiles and runs exactly how I need it to, however I will need to be able to add new components to the C# form in the future. Anyone got any ideas on how I can get the Visual Studio design view working?

Here's a very simplified version of what I have:

Delphi Code:

type
  TMyDelphiForm = class(TForm)

  private
    ...
  public
    constructor Create(Sender : TObject);
  end;

implementation

  Constructor TMyDelphiForm.Create(Sender : TObject);
  begin
    inherited;
  end;

C# Code:

public partial class MyCSharpForm : TMyDelhpiForm
{
  public MyCSharpForm(Component sender) : base(sender);
  {
    InitializeComponent();
  }
}

Thanks in advance

4
I am using CodeGear RAD Studio 2007Stuart
Are you using VCL.Net? AFAIK this is not based on WinForms, so you probably won't be able to use it with an WinForms designer.Uli Gerhardt

4 Answers

4
votes

You cannot mix and match Win Forms and VCL Forms in the same application - period. They are two separate Windows frameworks and are not compatible. The only way to go is to redo the GUI in Visual Studio and link to your non-GUI components built as assemblies through the Delphi.NET compiler.

1
votes

The designer requires a public parameterless constructor on the base class to work.

Dependant on the implementation of your base class, this might or might not be a show stopper. You may be able to solve the problem by adding something like:-

public MyCSharpForm() : base (null)
{
}

to your c# form. But you will need to ensure that the base class behaves properly at design time (ie, rendering logic can cope with the null, or whatever static value you provide for Sender.

0
votes

I would add a base C# class that inherits from the TMyDelphiForm, and put all my Delphi / C# mapping code in there, in case I need to derive more than one C# form from the Delphi form, something like:

public class MyCSharpFormBase : TMyDelphiForm
{
    public MyCSharpFormBase() : base (null) { } 
}

and then inherit your form from MyCSharpFormBase. Haven't tried it, but I think it will satisfy the designer.

0
votes

Do you have the source code for the delphi class? can you see what it does with the object/Component Sender parameter?

If you can instantiate something that will satisify the delphi class easily, then you can probably get designer support with an intermediate class that called the base like this:-

    public class MyIntermediateClass : MyDelphiForm
    {
      public MyIntermediateClass() : base(new Component())
      {
      }
    }

And then have your designable form inherit MyIntermediateClass