Delphi to C++ property issue [Edit]

Hi All,
I was compiling a Delphi third party library in C++. I fixes a few issues and left to this. It seems compiler has some problem when it comes to index and array in property. Separately seems to be fine. Solutions/fixes to pas file or other pointers greatly appreciated.

*Works*
Pascal:
{code}
property Attributes[const aName: OWideString]: OWideString read GetAttribute write _SetAttribute;
function GetAttribute(const aName: OWideString): OWideString;
{code}
C++:
{code}
__property System::UnicodeString Attributes[const System::UnicodeString aName] = {read=GetAttribute, write=_SetAttribute};
System::UnicodeString __fastcall GetAttribute(const System::UnicodeString aName);
{code}
*Works*
Pascal:  
{code}
TXMLChildType = (ctChild, ctAttribute);
property FirstAttribute: PXMLNode index ctAttribute read GetFirstCChild;
function GetFirstCChild(const aChildType: TXMLChildType): PXMLNode;
{code}
C++:
{code}
__property PXMLNode FirstAttribute = {read=GetFirstCChild, index=1};
PXMLNode __fastcall GetFirstCChild(const Oxmlutils::TXMLChildType aChildType);
{code}
*Doesn't Work*
Pascal:
{code}
property ChildFromBegin[const aIndex: Integer]: PXMLNode index ctChild read GetCChildFromBegin;
function GetCChildFromBegin(const aIndex: Integer; const aChildType: TXMLChildType): PXMLNode;
{code}
C++:
{code}
__property PXMLNode ChildFromBegin[const int aIndex] = {read=GetCChildFromBegin, index=0};
PXMLNode __fastcall GetCChildFromBegin(const int aIndex, const Oxmlutils::TXMLChildType aChildType);  
{code}
*Update:*
Error: +E2347 Parameter mismatch in read access specifier of property ChildFromBegin+

*OS*: Windows 7 64bit
*RAD*: XE 4, Update 1 
*Compiler*: 32 bit

Edited by: Mathew Joy on Jul 17, 2014 2:08 PM

Edited by: Mathew Joy on Jul 17, 2014 2:12 PM
0
Mathew
7/17/2014 9:13:14 PM
embarcadero.cppbuilder.cpp 2803 articles. 0 followers. Follow

8 Replies
1010 Views

Similar Articles

[PageSpeed] 51

Mathew wrote:

> It seems compiler has some problem when it comes to index and
> array in property. Separately seems to be fine. 

What exactly is not working correctly?  Please be more specific.  I don't 
see anything wrong with the code you have shown.

--
Remy Lebeau (TeamB)
0
Remy
7/17/2014 9:07:52 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Mathew wrote:
> 
> > It seems compiler has some problem when it comes to index and
> > array in property. Separately seems to be fine. 
> 
> What exactly is not working correctly?  Please be more specific.  I don't 
> see anything wrong with the code you have shown.
> 
> --
> Remy Lebeau (TeamB)
Sorry, I missed the error part. I updated the original post.

Regards,
Mathew Joy
0
Mathew
7/17/2014 9:11:41 PM
El 17/07/2014 22:56, Mathew Joy escribió:
> Hi All,
> I was compiling a Delphi third party library in C++. I fixes a few issues and left to this. It seems compiler has some problem when it comes to index and array in property. Separately seems to be fine. Solutions/fixes to pas file or other pointers greatly appreciated.
>

> *Doesn't Work*
> Pascal:
> {code}
> property ChildFromBegin[const aIndex: Integer]: PXMLNode index ctChild read GetCChildFromBegin;
> function GetCChildFromBegin(const aIndex: Integer; const aChildType: TXMLChildType): PXMLNode;
> {code}
> C++:

Why GetCChildFromBegin has two parameters?
0
Antonio
7/17/2014 9:16:23 PM
> {quote:title=Antonio Estevez wrote:}{quote}
> El 17/07/2014 22:56, Mathew Joy escribió:
> > Hi All,
> > I was compiling a Delphi third party library in C++. I fixes a few issues and left to this. It seems compiler has some problem when it comes to index and array in property. Separately seems to be fine. Solutions/fixes to pas file or other pointers greatly appreciated.
> >
> 
> > *Doesn't Work*
> > Pascal:
> > {code}
> > property ChildFromBegin[const aIndex: Integer]: PXMLNode index ctChild read GetCChildFromBegin;
> > function GetCChildFromBegin(const aIndex: Integer; const aChildType: TXMLChildType): PXMLNode;
> > {code}
> > C++:
> 
> Why GetCChildFromBegin has two parameters?
Didn't understand. It has two parameters. Apparently to differentiate between ChildType. So ChildFromBegin property is mapped to ctChild. It is an enum as shown in the OP. Thanks.

Regards,
Mathew Joy
0
Mathew
7/17/2014 9:22:57 PM
Antonio wrote:

> Why GetCChildFromBegin has two parameters?

The first parameter receives whatever value the caller passs to the brackets, 
the other parameter receives the value specified in the 'index' specifier 
of the property declaration.

So, given this property declaration:

{code}
__property PXMLNode ChildFromBegin[const int aIndex] = {read=GetCChildFromBegin, index=0};
{code}

This code:

{code}
PXMLNode node = obj->ChildFromBegin[index];
{code}

Would translate to this call:

{code}
PXMLNode node = obj->GetCChildFromBegin(index, ctChild); 
{code}

That is why the getter has to have 2 parameters.

--
Remy Lebeau (TeamB)
0
Remy
7/17/2014 9:53:51 PM
> {quote:title=Mathew Joy wrote:}{quote}
> I was compiling a Delphi third party library in C++. I fixes a few issues and left to this. It seems compiler has some problem when it comes to index and array in property. Separately seems to be fine. Solutions/fixes to pas file or other pointers greatly appreciated.

My guess would be that the Delphi compiler has issues with mixing array properties and index specifiers together (it certainly has problems generating useful RTTI for it).  You may end up having to tweak the source code to replace the getter with a different version that dos not use an index specifier:

Pascal:

{code}
property ChildFromBegin[const aIndex: Integer]: PXMLNode {index ctChild} read {GetCChildFromBegin}GetCChildFromBegin2;
function GetCChildFromBegin(const aIndex: Integer; const aChildType: TXMLChildType): PXMLNode;
function GetCChildFromBegin2(const aIndex: Integer): PXMLNode;

function TTheParentClass.GetCChildFromBegin2(const aIndex: Integer): PXMLNode;
begin
  Result := GetCChildFromBegin(aIndex, ctChild);
end;
{code}

C++:

{code}
__property PXMLNode ChildFromBegin[const int aIndex] = {read=GetCChildFromBegin2};
PXMLNode __fastcall GetCChildFromBegin(const int aIndex, const TXMLChildType aChildType);
PXMLNode __fastcall GetCChildFromBegin2(const int aIndex);
{code}

--
Remy Lebeau (TeamB)
0
Remy
7/17/2014 10:00:06 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> > {quote:title=Mathew Joy wrote:}{quote}
> > I was compiling a Delphi third party library in C++. I fixes a few issues and left to this. It seems compiler has some problem when it comes to index and array in property. Separately seems to be fine. Solutions/fixes to pas file or other pointers greatly appreciated.
> 
> My guess would be that the Delphi compiler has issues with mixing array properties and index specifiers together (it certainly has problems generating useful RTTI for it).  You may end up having to tweak the source code to replace the getter with a different version that dos not use an index specifier:
> 
> Pascal:
> 
> {code}
> property ChildFromBegin[const aIndex: Integer]: PXMLNode {index ctChild} read {GetCChildFromBegin}GetCChildFromBegin2;
> function GetCChildFromBegin(const aIndex: Integer; const aChildType: TXMLChildType): PXMLNode;
> function GetCChildFromBegin2(const aIndex: Integer): PXMLNode;
> 
> function TTheParentClass.GetCChildFromBegin2(const aIndex: Integer): PXMLNode;
> begin
>   Result := GetCChildFromBegin(aIndex, ctChild);
> end;
> {code}
> 
> C++:
> 
> {code}
> __property PXMLNode ChildFromBegin[const int aIndex] = {read=GetCChildFromBegin2};
> PXMLNode __fastcall GetCChildFromBegin(const int aIndex, const TXMLChildType aChildType);
> PXMLNode __fastcall GetCChildFromBegin2(const int aIndex);
> {code}
> 
> --
> Remy Lebeau (TeamB)
I get what you are saying. For now I exposed the Getter and commented out the property. Your solution will become handy. Thank you Remy.

Regards,
Mathew Joy.
0
Mathew
7/17/2014 10:03:43 PM
El 17/07/2014 23:53, Remy Lebeau (TeamB) escribió:
> Antonio wrote:
>
>> Why GetCChildFromBegin has two parameters?
>
> The first parameter receives whatever value the caller passs to the brackets,
> the other parameter receives the value specified in the 'index' specifier
> of the property declaration.
>

Thanks.
0
Antonio
7/17/2014 10:07:44 PM
Reply:

Similar Artilces:

Import C or C++ DLL in Delphi [Edit]
Hello, usually I can import a dll written in C in Delhi. To do that I write a unit (wrapper.pas) to link the dll with my VCL project. example: {code} function UCC_OpenCamera(CamId: LongWord; SpeedLimit: integer): UNI_RETURN_TYPE; stdcall external 'UniControl.DLL'; {code} This way works fine for me but it requires writing a lot of code to translate all calls and types in delphi. There isn't another way to "convert/import automaticcally" the .dll? 1) Can I create a package inside C++ Builder and use it inside Delphi? 2) The command line tools IMPLIB.EXE (for ...

Re: calling a c++ function from Delphi [Edit] [Edit]
costa basil wrote: > Sorry, I posted it here because different people read different lists > and c++ guys might not read the delphi lists and vice-versa and I > want to pick-up all brains... And yet, it is not allowed. -- Rudy Velthuis (TeamB) http://www.teamb.com "This isn't right, this isn't even wrong." -- Wolfgang Pauli (1900-1958), upon reading a young physicist's paper ok, understood. ...

BUG (or issue) with Indy, C++ Builder 2010 and C++ Builder XE [Edit]
To reproduce this issue you need a clean installation (from scratch, no additional components installed, no Indy update) of C++ Builder 2010 or XE. It uses Indy 10.5.5 (with 2010) or 10.5.7 (with XE). Note: although it uses Indy to reproduce the issue, the version of Indy and Indy itself is not the one that causes this problem but the linking of C++ binary probably. Steps to reproduce: 1. Create a simple text file with the following content. Save it as "file.txt" or any other name. It can be also full email message but the text below is enough. {code} Subject: =?windows-125...

C++ to Delphi [Edit]
Hello! Can someone please convert this DLL source to Delphi {code:c++} // HookDLL.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "HookDLL.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { //Flesh out the entry point pending full implimentation // reserve the DLL handle ghModule = (HINSTANCE)hModule; // register system-wide message SWM_TRAYMSG = RegisterWindowMessage("TRAY_ACTIVATED"); // will be used ...

More C to Delphi [Edit]
Hi, what's the equivalent code in Delphi for: 1) typedef struct _cl_device_id * cl_device_id; 2) #define CL_FLT_MAX 0x1.fffffep127f #define CL_FLT_MIN 0x1.0p-126f #define CL_FLT_EPSILON 0x1.0p-23f they're 1.0 * 2^127, 1.0*2^-126 and 1.0*2^-23, but is there any way to represent them in Delphi with consts, except for approximating? edit: well 0x1.fffffep127f isn't 1.0 * 2^127 actually, mis-read it. Thanks, Dan. Edited by: Daniel Bartlett on Mar 15, 2009 3:03 AM Daniel Bartlett wrote: > Hi, > > what's th...

C# covert to delphi [Edit]
private string HostEncode(string InVal) { string NewVal = string.Empty; int pos = 0; foreach (char c in InVal) { char NewChar = (char)0; pos++; switch (pos) { case 1: NewChar = (char)(c + 12); break; case 2: NewChar = (char)(c + 7); break; case 3: NewChar = (char)(c + 3); ...

C++ and Delphi compatibility [Edit]
I wanted to put this out there and get your opinions. I've been working on kind of large C++ library which tries borrow as many idioms from Delphi and C# as possible, which can integrate well with Delphi (and Free Pascal), and works on all platforms. It's ready for me to release but I want to write a few more demos. It'll be on git hub or some other public open source repository soon. Here is a test application I ran this morning which exports Delphi functions and interface objects to a C++ application: http://codebot.org/c-code.txt 3 files. Delphi source unit, C++ head...

C++ conver to Delphi [Edit]
Hello! can some please convert this code into delphi ###################################### unsigned char numItems = packet->contents(1); for (int i = 0; i < numItems; i++){ unsigned short serial; memcpy_s(&serial, 2, &packet->contents((i*11)+2), 2); unsigned char coordx = packet->contents((i*11)+4); unsigned char coordy = packet->contents((i*11)+5); unsigned char group = packet->contents((i*11)+11) >> 4; unsigned char subindex = packet->contents((i*11)+6); unsigned char lvlInfo = packet->contents((i*11)+7); unsigned char...

linking delphi DLL in C++ [Edit]
Hi, i have question. I created DLL with one procedure and want use it in my C++ project. test DLL: {code} library TestDLL; uses SysUtils, Classes, Dialogs; procedure DllMessage; export; begin ShowMessage('Hello world from a Delphi DLL') ; end; exports DllMessage; begin end. {code} I thought that i can load the DLL like {code} const HMODULE hWtsHnd = LoadLibrary("TestDLL.dll"); whattype DLLProcedure = (whattype) GetProcAddress(hWtsHnd, "DllMessage"); {code} I'm new to dlls, what type should by the DLLProcedure? ...

C++Builder and PHP Delphi [Edit]
1. I upgraded from C++Builder 2009 professional to C++Builder 2010 professional before September 24 2009, so I could get another product for free, and I choose Delpi PHP. 2. I have never used Delphi, but know PHP fairly well. I think PHP 6 will be great. My question is. Is Delphi PHP, PHP, Delphi or a combination? 3. In referring to Bjarne Strostrup (August 1992) "The C++ Programming Language Second Edition" chapter 4.4 "Linkage to Non-C++ Code" I wonder, will Delphi PHP be an ideal language to combine the flexibility of PHP (see code snippet below) wit...

Delphi 2010 TRichEdit issues [Edit]
I am migrating an old application coded in D2007 to D2010. I have found 2 issues with TRichEdit. 1) When the property ScrollBars is set to scBoth, changing the Wordwarp property does nothing. In D2007 and older versions changing Wordwarap to true automatically hided the horizontal scrollbar. Now to get the same effect you need 2 lines of code,: re.Wordwrap:= not re.Wordwrap; if re.Wordwrap then re.Scrollbar:= ssVertical else re.Scrolbar:= ssBoth; This is a big deal when the richedit contains a large number of lines because this causes the rich edit to repaint twice. 2) When ...

comparate component (delphi to c++) [Edit]
In delphi is: {code} if Components[i] is TLabel then begin ... end {code} how to do this in c++? Il Fri, 17 Dec 2010 08:06:02 -0800, dario acosta <> ha scritto: >In delphi is: >{code} > if Components[i] is TLabel then begin > ... > end >{code} > >how to do this in c++? {code} if ( dynamic_cast<TLabel*>( Components[i] ) ) { ... } {/code} Or, if you need for the "refined" pointer to the TLabel obj in the "if" block: {code} if ( TLabel* const Label =...

How do I convert this Delphi to C++Builder? [Edit]
I have spent two days trying to get the idea of converting the following Delphi to C++Builder, but to no avail. This code is part of an ActiveX client program. Data types of variables +V.Collection+ and +V.Collection.Item()+ do not appear in _TLB.h and _OCX.h created from imported type library. Hence I fail to borrow the idea Remy kindly offered in this thread: https://forums.embarcadero.com/thread.jspa?threadID=72273&tstart=0 I would much appreciate if any kind soul will relieve my pain by converting this code to BCB for me so that I can crawl upward slowly. The document for t...

calling a c++ function from Delphi [Edit]
Could someone please point me to an article (web, documentation) that shows how to implement a c/c++ function that takes a string and returns a string as output parameter. I want to call this method from delphi. So far I tried: c++: __declspec( dllexport ) __fastcall int method(const System::String inputString, System::String& outputString) { int rc = -1; ..... outputString += <some value>; ..... return rc; } delphi: function method(inputString: String; var outputString: String): integer; external 'method.dll' name '@method$qqrx20System@UnicodeString...

Web resources about - Delphi to C++ property issue [Edit] - embarcadero.cppbuilder.cpp

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Thousands of dollars of property stolen from Port Augusta home during Christmas break-in - AdelaideNow ...
DEFENCE medals and unique jewellery are among thousands of dollars of property stolen during a break-in at a Port Augusta home over Christmas. ...

Fire damages Auburn property belonging Salim Mehajer's sister
A property belonging to the sister of the controversial Auburn deputy mayor has been damaged in a suspicious fire overnight.

Police raid elaborate underground hydroponic set-up in remote property
An eight-year-old boy was discovered locked in a tiny room within a shed on a remote property where his family allegedly built one of the most ...

Mount Isa Police crackdown nets 20 people over property theft - The Courier-Mail Search Search
ABOUT 20 people have been charged, including 17 juveniles, after a series of break and enters and thefts in Mount Isa.

Bomb squad called to Qld property
TWO men have been charged after police found explosives at a property in Helidon.

Fire damages Auburn property belonging Salim Mehajer's sister
A property belonging to the sister of the controversial Auburn deputy mayor has been damaged in a suspicious fire overnight.

Macquarie Bank makes a bid for property portal, onthehouse.com.au
Property software and online services company Onthehouse Holdings Limited has received an unsolicited takeover offer from a consortium led by ...

Police raid elaborate underground hydroponic set-up in remote property
An eight-year-old boy was discovered locked in a tiny room within a shed on a remote property where his family allegedly built one of the most ...

Resources last updated: 1/8/2016 5:13:40 AM