Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

abstruct properties

Posted on 1998-11-19
3
Medium Priority
?
161 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 40 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 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