?
Solved

Inheritance Strategy

Posted on 2005-03-14
3
Medium Priority
?
221 Views
Last Modified: 2013-11-25
Greetings,
I am a bit stumped on how to use inheritance to solve my problem. I am using a non-MDI interface main form that creates and displays user controls (rather than new forms) to display data to the user for browsing and editing. I have a base class called ViewPane. All viewpanes will have a grid style list control and a dataset, however they will each naturally have different schemas. Most of the methods of the viewpane are generic in that they apply to every viewpane such as navigating records and reacting to application events such as cut and paste. Some of the methods apply to all instances but are implemented in different ways such as updating records. I have the concept of overrides somewhat down, but it will not let me override an object declaration on the base class.

I tried to add an untyped dataset and an unbound grid to my base, but I couldnt modify these in the inherited controls. I then tried to add a new strongly typed dataset and bound grid with the same names as the base class controls to the inherited control using the Shadows keyword and this didnt have the results I expected. Mostly got "Object reference not set to an instance..." errors. As I write this it occurs to me that maybe I should be trying to modify the dataset and grid in code at run time rather than in the designer at design time??

I don't want to rewrite code to manage all these grids and datasets on each user control that is identical just because the grids and datasets are not indentical. Help!
Thanks :)


0
Comment
Question by:cbasulto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Assisted Solution

by:Chipzter
Chipzter earned 1000 total points
ID: 13542406
Perhaps you could declare the objects that are to be overridden in the subclasses as protected readonly properties? It would also be prettier to make the super class MustInherit and the properties MustOverride, but that would break the designer.

A pseudo example:

Public Class FormBase
    Inherits System.Windows.Forms.Form

   '....

  System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '...
        Me.DataGrid1.DataSource = Me.FormDataSet
        '...
  End Sub

  Protected Overridable ReadOnly Property FormDataSet() As DataSet
        Get
            Return theDefaultDataSet
        End Get
  End Property

  '...
End Class

Public Class Form1
    Inherits FormBase
    '...
    Protected Overrides ReadOnly Property FormDataSet() As DataSet
        Get
            Return theOverriddenDataSet
        End Get
    End Property
    '...
End Class
0
 
LVL 27

Accepted Solution

by:
BigRat earned 1000 total points
ID: 13543797
If I understand you correctly it's like having :-

    TMyCustomForm = class(TCustomForm)
                                 Grid : TCustomGrid;
                                  DataSet : TCustomDataSet;
                                  Button1 : TButton;

                                  procedure OnButton1Do;
 
                                 end;

You then program OnButton1 (inter alia) to perform actions on the Grid and the dataset.

Later you actually define the real objects by "filling in" the asbtract classes.

Of course this won't work!

What ones does however is to define the abstract objects via interfaces and code up the standard actions against those interfaces. When you define the "real" form your constructor "constructs" those objects (assuming of course they match the interfaces).

HTH
0
 

Author Comment

by:cbasulto
ID: 13545090
I am going to use both of these solutions. I realized after more thought that many of the methods were extensions of either the dataset or the datagrid class, so I am going to inherit from these and create extended classes which I can use in my forms with fewer lines of code, but in some implementations being able to pass the overridden object as a property would work well.

Thank you very much.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question