Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions related to _property and form 2

Status
Not open for further replies.

hajimeml

Programmer
Apr 17, 2009
18
0
0
CN
Hello. I found the following statement from the program I try to understand. Could you please let me know what it is supposed to do?

editFBG1->Value = CTG->GetFBG1()

where
- editFBG1 is a pointer to TDoubleEdit.
- It is also a _published member of TFormCT
- CTG->GetFBG1() returns a value of type double

Inside the file DoubleEdit.h, I found:

class PACKAGE TDoubleEdit : public TEdit
{
protected:
double FValue;
__published:
_property double Value = {read=FValue, write = SetValue};
};

Q1: What does editFBG1->Value = CTG->GetFBG1() means?
My understanding is that it sets Value of
type _property in the class TDoubleEdit to the
value (of type double)returned from
CTG->GetFBG1() on the right. Am I correct?

Q2: I don't really know what _property is but from the
help file, it looks like it is a property of a form
in Builder. However, I cannot find this property
field in the object inspector of the corresponding
form. I am confused. Could you please clarify?

Q3: As you see, FValue is defined in class TDoubleEdit.
However, I cannot find the variable SetValue being
defiend there. There is a protected function
void __fastcall SetValue(double val) defined in
that clas though. They are probably unrelated.
Do you think SetValue is being defined in TEdit?

Q4: Where is the class TEdit located? I can see lots of
class being listed in the class explorer. However,
I cannot find TEdit there.

Thanks.
 
Q1: What does editFBG1->Value = CTG->GetFBG1() means?
My understanding is that it sets Value of
type _property in the class TDoubleEdit to the
value (of type double)returned from
CTG->GetFBG1() on the right. Am I correct?

Correct.

Q2: I don't really know what _property is but from the
help file, it looks like it is a property of a form
in Builder. However, I cannot find this property
field in the object inspector of the corresponding
form. I am confused. Could you please clarify?

The properties of each VCL component is different and can be inherited or derived from other VCL components. For example, if you look at TEdit in the help file, you will notice that there are links to properties, methods, and events. Some of these properites will show up in the object inspector; AutoSelect, AutoSize, BorderStyle, CharCase, etc.. Some of these are derived from other components so you will see them elsewhere, too.

Q3: As you see, FValue is defined in class TDoubleEdit.
However, I cannot find the variable SetValue being
defiend there. There is a protected function
void __fastcall SetValue(double val) defined in
that clas though. They are probably unrelated.
Do you think SetValue is being defined in TEdit?

_property double Value = {read=FValue, write = SetValue}; means that the property value can be read or set with a value you supply. For example,
Code:
// This code set the value of editFBG1 to CTG->GetFBG1()
editFBG1->Value = CTG->GetFBG1();

// This code gets the value of editFBG1 and puts it into MyDouble
double MyDouble = editFBG1->Value;

Some properties are readable only, some are setable only, and some, like Value are both. All SetValue is is a method that takes a string from the object inspector and converts it to an appropriate value the property can use.

Q4: Where is the class TEdit located? I can see lots of
class being listed in the class explorer. However,
I cannot find TEdit there.

Off the top of my head, I don't know. It is possible that it is inheriting its properties from other classes to you would have to go through other classes to find it. I used to have a chart of which class inherited what and where but I can't find it.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Code:
__property double Value = {read=FValue, write = SetValue};
This means that TDoubleEdit is declaring a property called Value that is of type double. When this property is read, it does so by directly accessing FValue. When it's written to, it will do so by calling a method named SetValue which takes one parameter of type double. In this particular case the method is a private one, which is the standard way of declaring a "Setter."

You can also use __property to specify a "Getter" method to retrieve the Value like so:
Code:
__property double Value = {read=GetValue, write=SetValue};
You use property's just like you would any public field in a class:
Code:
  double D = editFBG1->Value; // reading the property
  editFBG1->Value = 1.314159; //writing to the property;
Using Getters and Setters is done so the class can perform error checking or conversion manipulations on the data, as well as preserving data encapsulation.

As far as TEdit's definition, try looking in stdctrls.hpp. TEdit is part of the VCL's StdCtrls Unit, and stdctrls.hpp is the Header file for that unit, which will be located in the \include\vcl folder of your BCB folder (at least in BCB5, anyway.)
 
Thank you for all of your help.

>When it's written to, it will do so by calling a method >named SetValue which takes one parameter of type double. >In this particular case the method is a private one, which >is the standard way of declaring a "Setter."

SetValue looks like a variable than a function/method to me.
Shouldn't a function be something like SetValue()?

From you post, it looks like if a function is a "Setter", it can be written so that it looks like a variable with only the name displayed.

How can you tell whether a name is the name of a variable or a Setter function then? Is it because there is a word "_property" at the front? If so, why we consider FValue as the name of a variable?
 
The "Setter" and "Getter" functions are "special" functions that follow the following form (per Your example)
Code:
class TSomeClass
{
...
// this section is usually set to private, but does not have to be
  void SetValue(double VAL);
  double GetValue(void);
...
published: // can also be public or even private, but private properties are unnecessary
  __property double Value = {read=GetValue, Write=SetValue};
...
}  //End of TSomeClass Decl
The first parameter for the Setter and the return type of the Getter MUST be of the same type as the property. The compiler will automatically pass the parameter to the Setter function, and assign the returned value from the Getter function, so all you have to code is:
Code:
   double test = editFBG1->Value;
   editFBG1->Value = 3.14159;
In the given situation, your code is using a Setter function (SetValue), but directly accesses the data field instead of using a Getter.
If you have ever coded with Visual Basic, this follows the same principle as the Property Get and Property Set methods.
 
Thank you Prattaratt and 2ffat for the nice explainations.

>The properties of each VCL component is different and can >be inherited or derived from other VCL components. For >example, if you look at TEdit in the help file, you will >notice that there are links to properties, methods, and >events. Some of these properites will show up in the >object inspector; AutoSelect, AutoSize, BorderStyle, >CharCase, etc.. Some of these are derived from other >components so you will see them elsewhere, too.

In the example shown in the original post, am I supposed to see Value in an object inspector? I cannot find it so far. Is there a good way to search for it?

Is TDoubleEdit an inherited class defined by the programmer or is it an inherited class defined in Borland Builder? A search in google shows that other people also used TDoubleEdit. Not sure if it is a coincidence.
 
In the example shown in the original post, am I supposed to see Value in an object inspector? I cannot find it so far. Is there a good way to search for it?

In some cases, yes, you will see a value if there is a default. For example, on AutoSize the default is false. In the object inspector, you will see a dropdown next to AutoSize with false as the default.

In your example, I believe the object inspector will show this as the Text property. The default for this is the name of the component or TEdit. Someone please correct me if I'm wrong on that.

Is TDoubleEdit an inherited class defined by the programmer or is it an inherited class defined in Borland Builder?
In Builder 6 and earlier, it must be defined by the programmer. I'm not certain about the newer versions, though.



James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Thanks, James. I had a quick look on the object inspector. There is no Text property in it.
 
What component are you using? Is it the TEdit box or something related? Also, what version of Builder are you using?


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I am using Borland Builder C++ Professional version 6.
As for your other questions, I have no idea. I am very sorry. I am just trying to understand and modify the program written by others. Is there a way to find out the answers to your questions?
 
What properties are in the object inspector for this component?

I'm surprised that Text doesn't show up. I suspect that this may be a derived component.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Sorry. When you say "this component", what do you mean?
 
When you have the source file in Builder, click on editFBG1. That is the component I'm talking about. The object inspector should list its properties.




James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I am very sorry for my lack of knowledge. Is editFBG1 supposed to be in a form?

I found editFBG1 in the .h file. It is defined as:

TDoubleEdit *editFBG1;

Then, under Builder, I chose switch between unit and form. Several form reading error messages appeared and I chose to ignore in each case. After several clicks on the ignore button, a form was displayed on the screen. I moved the cursor on the components being displayed on the form but none of them is called editFBG1.

The Form reading error message is like:

Cannot find class TDoubleEdit. Do you want to ignore the error and continue? Important: If you ignore the error, it is possible that the component or property will be lost.

After I clicked the ignore button, error messages for not being able to find classes TDoubleUpDown, TUIntEdit, TUIntUpDown were displayed one by one.
 
Ah. I understand. TDoubleEdit must have been defined by the programmer somewhere unless the source code comes from a newer version of Builder. In BCB6 it is not defined in VCL or as a component.

In this case, you will not find a text property. I assume it will only accept floating point numbers.

James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top