473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to implement "__property" in ANSI C++ ?

Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how
one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}
Jul 22 '05 #1
7 4780

<David> wrote in message
news:41***********************@news.optusnet.com.a u...
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}


There is no way to make that code compile in standard C++. Are you asking
how to rewrite it into standard C++? If so then try this

class TMyClass
{
private:
int FMyVariable;
public:
void SetMyVariable(int Value) { FMyVariable = Value;}
int GetMyVariable() const { return FMyVariable;}
};

TMyClass MyClass;

void TMyForm::Button2Click(TObject *Sender)
{
MyClass.SetMyVariable(1234);
Caption = IntToStr(MyClass.GetMyVariable());
}

john
Jul 22 '05 #2
David wrote:
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how
one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}


Macros? It would be pretty ugly, and you'd have to modify all the code.
Probably not worth it.

class C{
public:
DECLARE(int, MyVariable, GetMyVariable, SetMyVariable);
};

with
#define DECLARE(type, name, get, set) \
type name; \
type get()const{ return name; } \
type set(const type& t){ name = t; }

The other option is a preprocessor that runs over your code converting
the Borland syntax into real C++. This sounds easy.

Jacques.
Jul 22 '05 #3
<David> wrote in message
news:41***********************@news.optusnet.com.a u...
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?


There is no way other than get_Xyz and set_Xyz ... which involves rewriting
the
entire code.

Since Borland did not have BCB for others, I assume you use MS platforms.
Did you consider managed C++ ?
http://msdn.microsoft.com/library/de...__property.asp

Roman
Jul 22 '05 #4
<David> wrote in message news:<41***********************@news.optusnet.com. au>...
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how
one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}


How about using templates? You could do something like this -

template <typename T, typename C>
class Property
{
typedef T (C::*Get)() const;
typedef void (C::*Set)(T);
Get GetFunc_;
Set SetFunc_;
C & Class_;
public:
Property(Get GetFunc, Set SetFunc, C &Class)
: GetFunc_(GetFunc), SetFunc_(SetFunc), Class_(Class) {}

operator T () const
{
return (Class_.*GetFunc_)();
}

Property<T, C>& operator=(T val)
{
(Class_.*SetFunc_)(val);
return *this;
}
};

class TMyClass
{
int FMyVariable;
public:
Property<int, TMyClass> MyVariable;
TMyClass() : MyVariable(GetMyVariable, SetMyVariable, *this)
{
}
int GetMyVariable() const
{
return FMyVariable;
}
void SetMyVariable(int Value)
{
FMyVariable = Value;
}
};
Jul 22 '05 #5
Le vendredi 23 juillet 2004 à 11:35, David a écrit dans comp.lang.c++*:
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our
term to dump Borland (not only BCB).
As a part of my attempt to dump long-loved BCB I'm trying to investigate how
one can implement "__property" in ANSI C++.

Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}


What about the following?

class Int
{
private:
int IntValue_;
public:
Int & operator=(int Value) { IntValue_ = Value; }
operator int() const { return IntValue_; }
};

class TMyClass
{
public:
Int MyVariable;

};
TMyClass MyClass;

void __fastcall TMyForm::Button2Click(TObject *Sender)
{
MyClass.MyVariable = 1234;
Caption = IntToStr(MyClass.MyVariable);
}

--
___________ 2004-07-26 08:39:13
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
Jul 22 '05 #6
<David> wrote in message news:

As a part of my attempt to dump long-loved BCB I'm trying to investigate how
one can implement "__property" in ANSI C++.
The draft standard for C++/CLI includes 'property' with a different
(and better) syntax. In fact CLI objects are a ripoff of VCL objects.
You could wait around until either BCB 9 comes out, or some C++/CLI
compilers come out.
Would anyone have a solution hot to implement "__property" in ANSI C++ ie.
how to make following code compile in non-BCB C++ compiler?

class TMyClass
{
private:
int FMyVariable;
void __fastcall SetMyVariable(int Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVariable, write=SetMyVariable};

};


class MyClass
{
public:
int MyVariable;
};
Jul 22 '05 #7
You can try this mothod

class Test
{
private:
int _data;
public:
Test(int data ): _data(data){};
~Test(){};
int& Data(){ return _data; };
};

You, now, can both read a value and write a value.
Test t(10);
int i = t.Data(); // i == 10
t.Data() = 15; // i == 15
i = t.Data();
--
Tnk

Luca "Kleidemos" Francesca

Un computer a un altro quando si incontrano:
"Ciao, come ti boota oggi???"
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

100
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We...
5
by: celsius | last post by:
Hi all, please forgive me if this already posted many times. i was reading peter van der linden's book expert C programming. on page number 188,he is discussing about implementing finite state...
7
by: wwxw_0 | last post by:
I am going to have some look at the ansi C implemention source of linux, such as stdio, file operation and so on, Where can I get some source code, I have downloaded linux source code but I cann't...
15
by: Bart Vandewoestyne | last post by:
I'm having a .c source file which at the top contains the line #include <math.h> In that source file, i declare a function dt which in its body uses the lgamma function. `man lgamma' on my...
48
by: Daniele C. | last post by:
As soon as my sourceforge.net project gets approved, I am going to build a ncurses port to win32 bindable to sockets, e.g. allowing VT100/ANSI terminals and the creation of simple terminal servers...
83
by: sunny | last post by:
Hi All What is C99 Standard is all about. is it portable, i mean i saw -std=C99 option in GCC but there is no such thing in VC++.? which one is better ANSI C / C99? can i know the major...
7
by: Paul Connolly | last post by:
char *s = "Hello"; s = 'J'; puts(s); might print "Jello" in a pre-ANSI compiler - is the behaviour of this program undefined in any pre-ANSI compiler - or would it always have printed "Jello"...
127
by: bz800k | last post by:
Hi Does this code satisfy ANSI C syntax ? void function(void) { int a = 2; a = ({int c; c = a + 2;}); /* <<-- here !! */ printf("a=%d\n", a);
8
AmberJain
by: AmberJain | last post by:
HELLO, Is it necessary for a C programmer to have an ANSI C standard or it's sufficient to own Kernigham and Rithie's The C programming language? I know that the ritchie's book is quite brief...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.