Board index » cppbuilder » accessing a delphi procedure from BCB project

accessing a delphi procedure from BCB project


2004-10-04 10:10:11 AM
cppbuilder75
How does one access a procedure in a delphi unit that is part of a C++
builder project?
I know that BCB can compile the delphi unit, but how does one access
procedures and data within
the delphi unit from the BCB unit?
Thanks
Thomas
 
 

Re:accessing a delphi procedure from BCB project

Thomas,
Assuming that you have added the .PAS to the project the compiler will
create a .HPP file for the .PAS file. Your .CPP unit needs to #include the
.HPP file and then call the functions as normal.
HTH,
- Clayton
 

Re:accessing a delphi procedure from BCB project

"Thomas" < XXXX@XXXXX.COM >wrote in message
Quote
How does one access a procedure in a delphi unit
that is part of a C++ builder project?
The IDE auto-generates an HPP header file for the Delphi code. Simply
include that HPP header file into your C++ code like any other header file.
Gambit
 

{smallsort}

Re:accessing a delphi procedure from BCB project

Thank you, the suggestions made by the two of you worked!!
Here is a follow up of what I am trying to do..maybe there is a better way
to do this
the procedure in my delphi unit is defined as such in the .hpp created by
c++ builder
================================================================
extern PACKAGE void __fastcall MoveNewHyperplane(Arraydecl::OneDimArray
NewHyp, Arraydecl::TwoDimArray CurrentConstr, double &MovedHypGamma);
==================================================================
arraydecl is another delphi unit which has also been added to the project
and its hpp declaration looks like this
=======================================
typedef DynamicArray<double>OneDimArray;
typedef DynamicArray<double>arraydecl__1;
typedef DynamicArray<DynamicArray<double>>TwoDimArray;
typedef DynamicArray<double>arraydecl__2;
============================================
So, in the C++ builder unit that accesses this procedure, How do I declare
my variables?
I tried pointers like double** etc but I am continually getting "type
mismatch" errors or "cannot convert " errors.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Thomas" < XXXX@XXXXX.COM >wrote in message
news:4160b187$ XXXX@XXXXX.COM ...

>How does one access a procedure in a delphi unit
>that is part of a C++ builder project?

The IDE auto-generates an HPP header file for the Delphi code. Simply
include that HPP header file into your C++ code like any other header
file.


Gambit


 

Re:accessing a delphi procedure from BCB project

"Thomas" < XXXX@XXXXX.COM >wrote in message
Quote
So, in the C++ builder unit that accesses this procedure,
How do I declare my variables?
Exactly as they are declared in the HPP file:
Arraydecl::OneDimArray NewHyp;
Arraydecl::TwoDimArray CurrentConstr;
double MovedHypGamma;
// fill in NewHyp and CurrentConstr as needed...
// assign MovedHypGamma as needed...
MoveNewHyperplane(NewHyp, CurrentConstr, MovedHypGamma);
// use MovedHypGamma as needed...
Quote
I tried pointers like double** etc but I am continually getting
"type mismatch" errors or "cannot convert " errors.
Please show your actual code.
Gambit
 

Re:accessing a delphi procedure from BCB project

Here are parts of the code.
double **ineqarray2=NULL;
.
double activeconstr[]={1,0,-1,0};
int inp_row,inp_col,i,j;
double &mygamma=NULL;
ineqarray2=(double **)malloc(4* sizeof(double *));
for (i=0;i<4 ;i++)
ineqarray2[i]=(double*)malloc(2*sizeof(double));
ineqarray2[0][0]= 0;
ineqarray2[0][1]= 1 ;
ineqarray2[0][2]= 0 ;
ineqarray2[0][3]= 0 ;
ineqarray2[1][0]= 0 ;
ineqarray2[1][1]= 0;
ineqarray2[1][2]= 1 ;
ineqarray2[1][3]= 0 ;
ineqarray2[2][0]= 0;
ineqarray2[2][1]= 0 ;
ineqarray2[2][2]= 0;
ineqarray2[2][3]= 1;
ineqarray2[3][0]= 1;
ineqarray2[3][1]= -1;
ineqarray2[3][2]= -1;
ineqarray2[3][3]= -1;
MoveNewHyperplane(ineqarray2, activeconstr,mygamma);
This is the original function in the hpp file (note that the last parameter
was originally a parameter of type var in delphi)
extern PACKAGE void __fastcall MoveNewHyperplane(Arraydecl::OneDimArray
NewHyp, Arraydecl::TwoDimArray CurrentConstr, double &MovedHypGamma);
P.S.: I am an old C user and not very familiar with C++ builder
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Thomas" < XXXX@XXXXX.COM >wrote in message
news:41617abb$ XXXX@XXXXX.COM ...

>So, in the C++ builder unit that accesses this procedure,
>How do I declare my variables?

Exactly as they are declared in the HPP file:

Arraydecl::OneDimArray NewHyp;
Arraydecl::TwoDimArray CurrentConstr;
double MovedHypGamma;

// fill in NewHyp and CurrentConstr as needed...
// assign MovedHypGamma as needed...

MoveNewHyperplane(NewHyp, CurrentConstr, MovedHypGamma);
// use MovedHypGamma as needed...

>I tried pointers like double** etc but I am continually getting
>"type mismatch" errors or "cannot convert " errors.

Please show your actual code.


Gambit


 

Re:accessing a delphi procedure from BCB project

"Thomas" < XXXX@XXXXX.COM >wrote in message
Quote
Here are parts of the code.
You are taking the completely wrong approach. The code expects you to use
the DynamicArray class, but you are not using it at all. The header files
even provide a few DynamicArray typedefs for you to use. Your code should
look more like the following instead.
Arraydecl::OneDimArray ineqarray2;
Arraydecl::TwoDimArray activeconstr;
double mygamma;
ineqarray2.Length = 4;
ineqarray2[0] = 1;
ineqarray2[1] = 0;
ineqarray2[2] = -1;
ineqarray2[3] = 0;
activeconstr.Length = 4;
for(int i = 0; i < 4; ++i)
activeconstr[i].Length = 4;
activeconstr[0][0]= 0;
activeconstr[0][1] = 1;
activeconstr[0][2] = 0;
activeconstr[0][3] = 0;
activeconstr[1][0] = 0;
activeconstr[1][1] = 0;
activeconstr[1][2] = 1;
activeconstr[1][3] = 0;
activeconstr[2][0] = 0;
activeconstr[2][1] = 0;
activeconstr[2][2] = 0;
activeconstr[2][3] = 1;
activeconstr[3][0] = 1;
activeconstr[3][1] = -1;
activeconstr[3][2] = -1;
activeconstr[3][3] = -1;
// look at the parameter order - the 1-dimensional array
// is the first parameter, not the second parameter. you had
// them reversed ...
MoveNewHyperplane(ineqarray2, activeconstr, mygamma);
Gambit
 

Re:accessing a delphi procedure from BCB project

Thank you Mr Lebeau. There was a lot of oversight from my part, sorry.
I tried to find about DynamicArray class on the web and in the C++ builder
books I have
but I did not find any documentation on it. That is why I just stuck to what
I knew about C programming.
Is it typical that one just studies the class definitions to understand how
it is used? Where can I read
more about dynamic arrays and their safe usage in a C++ builder project? I
want to know more about
initializing such arrays and about possible memory issues when dealing with
repeated assignment or large data.
Also , if I have defined some C++ builder functions like this :
extern "C" void GetExtremePts(double ***Ineq,int inprowsize,int inpcolsize);
can I use DynamicArray to define a variable given to this function(like the
***Ineq variable)?
Thanks again
Thomas
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Thomas" < XXXX@XXXXX.COM >wrote in message
news:41618990$ XXXX@XXXXX.COM ...

>Here are parts of the code.

You are taking the completely wrong approach. The code expects you to use
the DynamicArray class, but you are not using it at all. The header files
even provide a few DynamicArray typedefs for you to use. Your code should
look more like the following instead.

Arraydecl::OneDimArray ineqarray2;
Arraydecl::TwoDimArray activeconstr;
double mygamma;

ineqarray2.Length = 4;
ineqarray2[0] = 1;
ineqarray2[1] = 0;
ineqarray2[2] = -1;
ineqarray2[3] = 0;

activeconstr.Length = 4;
for(int i = 0; i < 4; ++i)
activeconstr[i].Length = 4;

activeconstr[0][0]= 0;
activeconstr[0][1] = 1;
activeconstr[0][2] = 0;
activeconstr[0][3] = 0;

activeconstr[1][0] = 0;
activeconstr[1][1] = 0;
activeconstr[1][2] = 1;
activeconstr[1][3] = 0;

activeconstr[2][0] = 0;
activeconstr[2][1] = 0;
activeconstr[2][2] = 0;
activeconstr[2][3] = 1;

activeconstr[3][0] = 1;
activeconstr[3][1] = -1;
activeconstr[3][2] = -1;
activeconstr[3][3] = -1;

// look at the parameter order - the 1-dimensional array
// is the first parameter, not the second parameter. you had
// them reversed ...

MoveNewHyperplane(ineqarray2, activeconstr, mygamma);


Gambit


 

Re:accessing a delphi procedure from BCB project

"Thomas" < XXXX@XXXXX.COM >wrote in message
Quote
I tried to find about DynamicArray class on the web and
in the C++ builder books I have but I did not find any
documentation on it.
DynamicArray is documented in the VCL help file. It is a compatibility
helper class. There are some native features of the Delphi Pascal language
that C++ does not have (dynamic arrays is one such feature), so Borland
provides various helper classes, such as DynamicArray, so that C++ code can
interface with Delphi code in a compatible manner.
Quote
Is it typical that one just studies the class definitions to
understand how it is used?
It can be.
Quote
Also , if I have defined some C++ builder functions like this :
extern "C" void GetExtremePts(double ***Ineq,int inprowsize,int
inpcolsize);

can I use DynamicArray to define a variable given to this function
(like the ***Ineq variable)?
A DynamicArray is not a raw array like you were trying to use. Anything
more than 1 dimensional arrays, you are going to have problems passing a
DynamicArray where a raw array is expected because the memory layous are
different.
Gambit