Board index » cppbuilder » Re: What is the upgrade for Borland C++ Builder 6?

Re: What is the upgrade for Borland C++ Builder 6?


2005-02-12 02:32:46 AM
cppbuilder20
Rudy Velthuis [TeamB] wrote:
Quote
Frank Staal wrote:

>On 10 Feb 2005 02:54:05 -0800, "Rudy Velthuis [TeamB]"
>< XXXX@XXXXX.COM >wrote:
>
>>Hmmm... could you post the code in the attachments group (I guess
>>such code is not really a trade secret, <g>) please? I'll try to
>>find my BCB6 CDs and install it here.
>Posted.

Installed BCB6 (really had to look for the CDs, since half of the
household is still in boxes) and tried the code.

There are two problems:

function BrowseForFoldery(Handle: HWND; const Title: string;
var Directory: string; Options: TBrowseOptions;
StartPoint: TSpecialFolder = sfDeskTop;
CallBack: TFNBFFCallBack = nil; CallBackParam: lParam = 0):
Boolean;

This did not link at all, as you said. So I first simplified it a bit:

function BrowseForFolder(Handle: HWND; const Title: string;
var Directory: string; Options: TBrowseOptions;
StartPoint: TSpecialFolder = sfDeskTop): Boolean;

Still didn't link. But then I replaced HWND (which is an unsigned in
Delphi, and a void* in C++) with THandle. This type is also an
unsigned in C++. Now I could call it with a cast:

if (BrowseForFolder((THandle)Handle, "Test", dir, options))
{
ShowMessage("Directory = " + dir);
}

When I tried to "unsimplify" this again, I still got a problem. I
guess that the TFNBFFCallBack function pointer type has a problem as
well. Will try to find out what. I guess it is a similar problem.
In shlobj.pas,
{$EXTERNALSYM BFFCALLBACK}
BFFCALLBACK = function(Wnd: HWND; uMsg: UINT;
lParam, lpData: LPARAM): Integer stdcall;
TFNBFFCallBack = type BFFCALLBACK;
The EXTERNALSYM means that the symbol BFFCALLBACK is not exported. But
TBFNFFCallback is exported, and this also uses HWND. Same problem.
I think it is time to ask Borland to use THandle exclusively. It would
have been better to make THandle, HWND etc. pointers instead, but it is
far tool ate for that. It would break too much existing code (including
the VCL).
I have no idea how TControl.Handle can be of a different type than
TControl::Handle, and still compile. TControl.Handle is an unsigned
int, and TControl::Handle is a void*.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"Humor is the only test of gravity, and gravity of humor; for a subject
which will not bear raillery is suspicious, and a jest which will not
bear serious examination is false wit." -- Aristotle (384 BC-322 BC)
 
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Rudy Velthuis [TeamB] wrote:
Quote
BCB6 uses the Delphi 6 compiler to compile .pas files, so that seems
unlikely.
That's what I thought. Finally I took the time and narrowed it down to
this code:
type
TMyIdentifier = array[0..15] of Byte;
TMyTable = class
private
function GetMyKey: TMyIdentifier;
public
property MyKey: TMyIdentifier read GetMyKey;
// A binary value that uniquely identifies [....].
end;
function TMyTable.GetInstanceKey: TMyIdentifier;
begin
end;
I hope I didn't make mistakes by deleting lines and changing names, in
order to keep the original source code to myself. It works very nicely
with Delphi. With BCB6 I get an error message:
[Pascal Error] *.pas: Unsupported language feature: 'property of array type'
This is why I wrote you originally that some Delphi language features
are not supported by BCB. You can call it a bug, or whatever, but this
is the truth.
Tom
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Tamas Demjen wrote:
Quote
Rudy Velthuis [TeamB] wrote:
>BCB6 uses the Delphi 6 compiler to compile .pas files, so that seems
>unlikely.

That's what I thought. Finally I took the time and narrowed it down
to this code:

type
TMyIdentifier = array[0..15] of Byte;

TMyTable = class
private
function GetMyKey: TMyIdentifier;
public
property MyKey: TRwMapiIdentifier read GetMyKey;
// A binary value that uniquely identifies [....].
end;

function TMyTable.GetInstanceKey: TRwMapiIdentifier;
begin
end;

I hope I didn't make mistakes by deleting lines and changing names,
You did, but I got it anyway.
Quote
in order to keep the original source code to myself. It works very
nicely with Delphi. With BCB6 I get an error message:

[Pascal Error] *.pas: Unsupported language feature: 'property of
array type'
That is weird indeed. It works in Delphi 7. I don't have Delphi 6 here
to check that.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"It's kind of fun to do the impossible."
- Walt Disney (1901-1966)
 

{smallsort}

Re:Re: What is the upgrade for Borland C++ Builder 6?

Tamas Demjen wrote:
Quote
type
TMyIdentifier = array[0..15] of Byte;

TMyTable = class
private
function GetMyKey: TMyIdentifier;
public
property MyKey: TMyIdentifier read GetMyKey;
// A binary value that uniquely identifies [....].
end;

function TMyTable.GetInstanceKey: TMyIdentifier;
begin
end;
Thinking about this a little bit, in C++ it's not possible to return an
array from a function. Although the compiler could simply generate
something like this, it wouldn't be the same at all:
class TMyTable : public TObject
{
private:
Byte* GetMyKey();
public:
__property Byte* MyKey { read=GetMyKey };
};
The reason is because the function GetMyKey is implemented like this:
function TMyTable.GetInstanceKey: TMyIdentifier;
begin
[...]
Move(MyPointer^, Result, 16);
end;
It clearly returns an array type value, and it's impossible to find a
direct equivalent for this in C++. One would have to rewrite some of the
code in order to support C++. After all, it's perfectly reasonable that
the code doesn't work in BCB. Surprising isn't it? Would you have
thought that there were Delphi features that couldn't be implemented in
C++, even with extending the language a little bit with keywords like
__property and __closure? Now this is one example.
*However*, we should be fair here. I would never ever use the MyKey
property myself from C++. It's an internal detail I don't care about.
The MyKey property is ONLY used by the Pascal code internally. So I'm
still saying that ommitting this property from the .hpp file would be a
better choice than a compiler error in this case. Or at least somehow
letting the compiler know that "OK, I acknowledge that this is no-no in
C++, but please, compile the Pascal code and leave this out of the
.hpp". Do you know by any chance if it can be done?
I can accept that there are limitations with the BCB-Pascal, but it's
not true that all Delphi language constructs work in BCB flawlessly.
Tom
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Rudy Velthuis [TeamB] wrote:
Quote
That is weird indeed. It works in Delphi 7. I don't have Delphi 6 here
to check that.
Delphi 6 ->OK
BCB 6 ->fails, but it's reasonable
Tom
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Tamas Demjen wrote:
Quote
This is why I wrote you originally that some Delphi language features
are not supported by BCB. You can call it a bug, or whatever, but
this is the truth.
Yes, you are right. I guess BCB could use an overhaul in the
compatibility department. <g>
BTW, I think it is not the Delphi compiler that has a problem with it,
it is BCB. If I comment out the property, the translation is still not
correct:
//-- type declarations
-------------------------------------------------------
typedef Byte TMyIdentifier[16];
class DELPHICLASS TMyTable;
class PASCALIMPLEMENTATION TMyTable : public System::TObject
{
typedef System::TObject inherited;
private:
Byte __fastcall GetMyKey();
As you see, GetMyKey() returns a byte, and not an array of 16 bytes.
Correct would have been:
void __fastcall GetMyKey(TMyIdentifier& Result);
Since that is how Delphi translates functions returning types larger
than 32 bits.
But that would have made GetMyKey() incompatible with a property.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"Why don't you write books people can read?"
- Nora Joyce to her husband James (1882-1941)
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Tamas Demjen wrote:
Quote
Tamas Demjen wrote:
>type
>TMyIdentifier = array[0..15] of Byte;
>
>TMyTable = class
>private
>function GetMyKey: TMyIdentifier;
>public
>property MyKey: TMyIdentifier read GetMyKey;
>// A binary value that uniquely identifies [....].
>end;
>
>function TMyTable.GetInstanceKey: TMyIdentifier;
>begin
>end;

Thinking about this a little bit, in C++ it's not possible to return
an array from a function. Although the compiler could simply generate
something like this, it wouldn't be the same at all:

class TMyTable : public TObject
{
private:
Byte* GetMyKey();
public:
__property Byte* MyKey { read=GetMyKey };
};

The reason is because the function GetMyKey is implemented like this:

function TMyTable.GetInstanceKey: TMyIdentifier;
begin
[...]
Move(MyPointer^, Result, 16);
end;

It clearly returns an array type value, and it's impossible to find a
direct equivalent for this in C++.
Actually, it is not really returned in Delphi either. GetMyKey() is
internally implemented as:
void __fastcall GetMyKey(MyIdentifier& Result);
Now if the .hpp generator would simply generate that, and if the
compiler would allow property getter functions to actually be like
that, it could be possible.
It would be a good idea to report this. It might be nice to have it
work in the new BCB (in Delphi IDE).
Actually ANY such incompatibilities should IMO be reported.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"He has all the virtues I dislike and none of the vices I admire."
-- Sir Winston Churchill (1874-1965)
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Rudy Velthuis [TeamB] wrote:
Quote
Actually ANY such incompatibilities should IMO be reported.
Oops, sorry for the overquote.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"The power of accurate observation is frequently called cynicism by
those who don't have it."
- George Bernard Shaw (1856-1950)
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Rudy Velthuis [TeamB] wrote:
Quote
Yes, you are right. I guess BCB could use an overhaul in the
compatibility department. <g>
PLEASE make sure to get any bug reports in for BCB ASAP so the team has
an opportunity to fix them before we release the C++ personality in the
next Delphi. (No, sorry, I have no release dates to announce.)
--
John Kaster blogs.borland.com/johnk
Features and bugs: qc.borland.com
Get source: cc.borland.com
What's going on? calendar.borland.com
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Tamas Demjen wrote:
Quote
Thinking about this a little bit, in C++ it's not possible to return
an array from a function.
Return a raw array by value? You are correct. You can get the effect
though by using boost::array.
This is simply a struct that contains the array, and overloads all the
necessary operators (eg operator[]) to act like a 'native' array. It
conveniently provides member functions to look like a standard
container too (eg. begin/end)
One of the less quoted benefits is that it copies-by-value, so if you
return a boost::array from a function it returns a copy of your array.
Very handy as a function parameter, as you can choose to pass by value
/ (const) reference, again not exactly simple with the native array.
And of course, coming soon to a Library TR...
That said, I would not recommend it for use with __property as
properties do not seem to work well with non_VCL types.
AlisdairM(TeamB)
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

John Kaster (Borland) wrote:
Quote
Rudy Velthuis [TeamB] wrote:

>Yes, you are right. I guess BCB could use an overhaul in the
>compatibility department. <g>

PLEASE make sure to get any bug reports in for BCB ASAP so the team
has an opportunity to fix them before we release the C++ personality
in the next Delphi. (No, sorry, I have no release dates to announce.)
Will report this one, and the HWND one. Anyone who knows others should
also report them.
--
Rudy Velthuis [TeamB] rvelthuis.bei.t-online.de
"The Stones, I love the Stones. I watch them whenever I can. Fred,
Barney..." -- Steven Wright.
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

John Kaster (Borland) wrote:
Quote
(No, sorry, I have no release dates to announce.)
You may want to add that to your signature line ;-)
--
Michael Gillen
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Michael Gillen wrote:
Quote
John Kaster (Borland) wrote:


>(No, sorry, I have no release dates to announce.)


You may want to add that to your signature line ;-)

I thought his sig was "when it's ready (tm)"
;-)
David Erbas-White
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Alisdair Meredith wrote:
Quote
This is simply a struct that contains the array, and overloads all the
necessary operators (eg operator[]) to act like a 'native' array. It
conveniently provides member functions to look like a standard
container too (eg. begin/end)

One of the less quoted benefits is that it copies-by-value, so if you
return a boost::array from a function it returns a copy of your array.
Very handy as a function parameter, as you can choose to pass by value
/ (const) reference, again not exactly simple with the native array.
But it has to be byte-compatible with the Pascal generated code, so it
can't be using boost, operator[], or anything like that.
Tom
 

Re:Re: What is the upgrade for Borland C++ Builder 6?

Rudy Velthuis [TeamB] wrote:
Quote
Actually, it is not really returned in Delphi either. GetMyKey() is
internally implemented as:

void __fastcall GetMyKey(MyIdentifier& Result);

Now if the .hpp generator would simply generate that, and if the
compiler would allow property getter functions to actually be like
that, it could be possible.

It would be a good idea to report this. It might be nice to have it
work in the new BCB (in Delphi IDE).

Actually ANY such incompatibilities should IMO be reported.
That's very interesting. Could you please take care of reporting this to
Borland? Just report it yourself, don't credit me for this. It would be
nice if Borland implemented it in the upcoming BCB-personality. This is
one incompatibility, and the other one is the HANDLE/HWND/HDC type in
the .hpp. Anybody who has a little free time could report these, the
entire community would benefit from such a fix.
Well, I did my part, it took me more than an hour to find the exact
location of the 'property of array type' error message, because the
compiler didn't point out its exact line number, but not even the exact
file in which it happened. The source code in question is very large. So
I had to remove half of the code manually, properties and functions one
by one, to find the offending line that way. It was very time consuming.
It's unfortunate that the compiler reported a very high line number that
didn't even exist. Some units had circular references, so I wasn't even
sure which .pas file caused the problem.
Thanks.
Tom