Solved

abstruct properties

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

10x
Asi
0
Comment
Question by:asi
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 199
creating threads in delphi 1 82
control image tags in a string ? 12 110
Unique identifier on a terminal server (rdp) 4 46
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now