473,800 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};
TMyClass MyClass;

void __fastcall TMyForm::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.MyVariable);
}
Jul 22 '05 #1
7 4797

<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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};
TMyClass MyClass;

void __fastcall TMyForm::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.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(i nt Value) { FMyVariable = Value;}
int GetMyVariable() const { return FMyVariable;}
};

TMyClass MyClass;

void TMyForm::Button 2Click(TObject *Sender)
{
MyClass.SetMyVa riable(1234);
Caption = IntToStr(MyClas s.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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};
TMyClass MyClass;

void __fastcall TMyForm::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.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.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?


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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};
TMyClass MyClass;

void __fastcall TMyForm::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.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_(GetFun c), SetFunc_(SetFun c), Class_(Class) {}

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

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

class TMyClass
{
int FMyVariable;
public:
Property<int, TMyClass> MyVariable;
TMyClass() : MyVariable(GetM yVariable, SetMyVariable, *this)
{
}
int GetMyVariable() const
{
return FMyVariable;
}
void SetMyVariable(i nt 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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};
TMyClass MyClass;

void __fastcall TMyForm::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.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::Button 2Click(TObject *Sender)
{
MyClass.MyVaria ble = 1234;
Caption = IntToStr(MyClas s.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(i nt Value) { FMyVariable = Value;}
int __fastcall GetMyVariable() { return FMyVariable;}
public:
__property int MyVariable = {read=GetMyVari able, write=SetMyVari able};

};


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
7029
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 are discussing whether this newsgroup should focus on 100% ANSI C or simply topics related to the C language in the real world. There is a C standard which is defined by an international committee. People who write compilers refer to this in...
5
1418
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 machine in C. he explains as follows :- there are several ways to implement finite state
7
2830
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 find anything about it. Does anybody know this? Thanks!
15
2961
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 linux system tells me that i have to include math.h so it seems like I'm doing the right thing in order to be able to use the lgamma function. When I compile the .c file with
48
4566
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 using the ncurses API for the UI. I plan to initially support only a subset of the ncurses lib, leaving the lib open to expansion/completion. Please stop me if I am going to reinvent the wheel, and tell me if there are any libraries of this...
83
11644
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 difference between C99 & ANSI C standards?
7
4858
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" with a pre-ANSI compiler? In gcc with the "writable-strings" option this program prints Jello If there were more than one semantics for what this progran did under a
127
5542
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
2069
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 and precise. But still, do I need a ANSI C standard? Also, Which ANSI C standard should I prefer i.e. ANSI C89 or ANSI C99 to implement in my C programs? Can you tell me pros and cons of both standards? Also, is there a newer standard in...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7576
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.