Search code examples
c#asp.netspread

Cannot call an abstract base member


I'm attempting to create a custom cell type for Spread.NET. The error I get is:

Cannot call an abstract base member: 'FarPoint.Web.Spread.BaseCellType.PaintCell(string, System.Web.UI.WebControls.TableCell, FarPoint.Web.Spread.Appearance, FarPoint.Web.Spread.Inset, object, bool)'

Here's the code:

[Serializable()]
public class BarcodeCellType : FarPoint.Web.Spread.BaseCellType
{
    public override Control PaintCell(string id, TableCell parent, Appearance style, Inset margin, object value, bool upperLevel)
    {
        parent.Attributes.Add("FpCellType", "BarcodeCellType");

        if (value != null)
        {
            try
            {
                MemoryStream ms = GenerateBarCode(value.ToString());
                var img = Bitmap.FromStream(ms);
                value = img;
            }
            catch (Exception ex)
            {
                value = ex.ToString();
            }
        }

        return base.PaintCell(id, parent, style, margin, value, upperLevel); //ERROR HERE
    }

    private MemoryStream GenerateBarCode(string codeInfo)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            BarCodeBuilder bb = new BarCodeBuilder();
            bb.CodeText = codeInfo;
            bb.SymbologyType = Symbology.Code128;
            bb.BarCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms;
        }
    }
}

Solution

  • It's because in your abstract class "FarPoint.Web.Spread.BaseCellType" you probably defined the PaintCell method as abstract and an abstract method declaration introduces a new virtual method but does not provide an implementation of that method. Instead, non-abstract derived classes ("BarcodeCellType") are required to provide their own implementation by overriding that method. Because an abstract method provides no actual implementation.