Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how do I add custom properties to an activeForm?

Posted on 1998-02-24
2
Medium Priority
?
194 Views
Last Modified: 2010-04-06
I am using the Edit | Add to Interface Option, on an ActiveForm which is blank (for testing). I type in a property name as property test:integer, and delphi 3 sets up the appropriate declarations in the code with the skeletons for the get and set methods. However, I cannot compile with  Result:=test in the get procedure, or test:=value in the set procedure....Please Help me solve this problem...
0
Comment
Question by:abdi
2 Comments
 
LVL 3

Accepted Solution

by:
philipleighs earned 800 total points
ID: 1359753
Hi,

You should not assign to or read a property from inside the Get or Set methods.
You should assign to and read from a private variable.

Here is some (rough) code: (there may be some syntax errors)

interface

type
  Tmyform = class( tform )
    private
       FMyVariable: Integer;  //this is where the number is *stored*
    protected
       function GetMyVariable: Integer;
       procedure SetMyVariable(AMyVariable: Integer);
    public
      property MyVariable: Integer read GetMyVariable write SetMyVariable;
   end;


implementation

function Tmyform.GetMyVariable: Integer;
   begin
      Result := FMyVariable;
   end;

procedure Tmyform.SetMyVariable(AMyVariable: Integer);
  begin
     FMyVariable := AMyVariable;
     //do other things here that care when MyVariable changes
  end;

end.


That is pretty much it. By the sounds of things, you don't have the private variable declaration. A property itself is not a variable. You must tell a property what variable/function/procedure to read and write to.

If you wanted to bypass the Get and Set routines you could change the property declaration to:

property MyVariable: Integer read FMyVariable write FMyVariable;

Good luck,
Phil.

0
 

Author Comment

by:abdi
ID: 1359754
philipleighs is correct....this really works....million thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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