Explain this notation: __property MyProperty = {read = *SomeObject, write = SomeMethod() } ?

Hi Im working with C++Builder6, Im learning Reports (TQuickRep).
I have an example but this is a bit confusing. Ive found this line in the Main form. I dont know what that line do, because the __property setting by a brackets {read = *TQuickRep, write = void SetReport(TQuickRep*) } ???

I think is like some pascal or delphi notation. If someone could explain that notation I'll be grateful.

1
2
3
4
5
6
7
// FORM .H (header)
private:	// User declarations
   TQuickRep * FReport;
   void SetReport(TQuickRep *);
public:		// User declarations
   __fastcall TMainForm(TComponent* Owner);
   __property TQuickRep * Report = {read = FReport, write = SetReport}; // what does this line do? 


Then the implementation of SetReport Method:
1
2
3
4
5
6
// FORM .CPP (implementation)
void TMainForm::SetReport(TQuickRep * Value)
{
   FReport = Value;
   Description->Lines->Assign(Report->Description);
}
Last edited on
It tells the compiler that when code does this:
1
2
3
//TMainForm form
form.Report = foo;
bar = form.Report;
it should rewrite it to this:
1
2
form.SetReport(foo);
bar = form.FReport();

Note that this is an extremely non-portable extension (although I wish something like this was in the language).
But what on earth is this line!
__property TQuickRep * Report = {read = FReport, write = SetReport};

__property is a typename - check.
TQuickRep is an identifier - check.
* means poiner - check.
Report - whaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat
= - assignment - check
{} - calling constructor?
, - okay separator operator - check
read and write are initialized - okay

Ahhh finally something I understand ; - USED TO TERMINATE STATEMENT YESSSSSSS.

Okay what the heck is that line though :'(
The problem is that you're trying to understand it from the point of view of C++. That line is not C++, it just looks superficially like it.

Broken down:
1
2
3
4
5
6
7
8
9
10
11
12
__property  // "The following declaration in this class is a property." A
            // property is a special way to access data in a class. See:
            // https://en.wikipedia.org/wiki/Property_(programming)
TQuickRep * // The type of the property.
Report      // The name of the property.
= {         // "OK, now I'm going to define the property."
read = FReport, // "When the property is read, use the function 'FReport' of
                // this class."
write = SetReport // "When the property is written, use the function 'SetReport'
                  // of this class.
}          // "I'm done defining the property."
;          // "I'm done with this declaration." 
Last edited on
If it's not C++, what is it? Why is it in a header file?
Last edited on
If it's not C++, what is it?
It's an extension to C++ specific to this compiler.

Why is it in a header file?
Because the class is defined in the header.
Saw c++builder bolrland6 works with delphi and pascal extensions.
but I think thanks @helios answer this topic clearly. Now is time to make some tests to see if this is true.

The only thing is that TQuickRep * FReport is not a method, is a pointer watch.
So everytime Report is accessed the compiler will read *FReport.

Edit*: I made some test that prove @helios was right. Again Thank you very much for your answer mr helios, I know you use to answer most question in this wonderful language. See you all.
Last edited on
Topic archived. No new replies allowed.