Solved

abstruct properties

Posted on 1998-11-19
3
144 Views
Last Modified: 2010-04-04
hi , does published/property can be abstruct ?

10x
Asi
0
Comment
Question by:asi
[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
  • 2
3 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347323
Only methods can be abstract.

Anything abstract has to also be virtual, and you can't have virtual properties.

Here is a workaround for:

property Size: Integer read FSize write FSize;

Change the property to methods:

function GetSize: Integer; virtual; abstract;
procedure SetSize(ASize: Integer); virtual; abstract;

The two methods would be implemented in a derived class, and the value would be stored in a variable in that derived class.

Cheers,
Phil.

0
 
LVL 1

Accepted Solution

by:
sassas081597 earned 20 total points
ID: 1347324
The compiler lets you to create a property as shown in previous comment, however you cannot use it in your programm - error arizes. For not having errors try to declare this property as protected.
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347325
Sassas,

You don't understand what *abstract* means.

If the error is "abstract error", it is because the derived class (you probably don't have one) is not implementing the methods.

Here is the idea for your benefit.

//The base class
type
   TBaseClass = class (TObject)
      public  //must be public in this example, var x (below) calls this method
           function GetSize: Integer; virtual; abstract;
           procedure SetSize(ASize: Integer); virtual; abstract;
   end;

//Ok, not notice that there is no implementation of TBaseClass.GetSize.
//TBaseClass represents an idea, not implemented code
//This is just how I think of it

//Now for the derived class
type
   TDerivedClass = class( TBaseClass)
      private
          FSize: Integer;
      public  //or it can be protected in this example
          function GetSize: Integer; override;
   end;

implementation

TDerivedClass.GetSize: Integer;
   begin
      Result := FSize;
   end;

//TDerivedClass.GetSize overrides TBaseClass.GetSize.

//Digest that for a while, now consider how to use this.
var x: TBaseClass;
begin
   x := TDerivedClass.Create;
   ShowMessage(IntToStr(x.GetSize));
   x.SetSize(50);  //<< this line causes an abstract run time error because
                          //TDerived class does not implement SetSize.
                          //The compiler will compile, but a warning will                           //be generated.
end;

//Calling x.GetSize will call the GetSize in TDerivedClass, not TBaseClass even though x is of type TBaseClass.

//x is of type TBaseClass, but it can be created using TDerivedClass since TDerivedClass is derived from TBaseClass


Just another thing, you shouldn't wrap up the essence of someone elses comment and try to get points for it.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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