Board index » cppbuilder » accessing a delphi procedure from BCB project
Thomas
![]() CBuilder Developer |
Thomas
![]() CBuilder Developer |
accessing a delphi procedure from BCB project2004-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 |
Clayton Arends
![]() CBuilder Developer |
2004-10-04 12:42:39 PM
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 |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-10-04 01:47:54 PM
Re:accessing a delphi procedure from BCB project
"Thomas" < XXXX@XXXXX.COM >wrote in message
QuoteHow does one access a procedure in a delphi unit Gambit {smallsort} |
Thomas
![]() CBuilder Developer |
2004-10-05 12:28:43 AM
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
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-10-05 12:59:28 AM
Re:accessing a delphi procedure from BCB project
"Thomas" < XXXX@XXXXX.COM >wrote in message
QuoteSo, in the C++ builder unit that accesses this procedure, Arraydecl::TwoDimArray CurrentConstr; double MovedHypGamma; // fill in NewHyp and CurrentConstr as needed... // assign MovedHypGamma as needed... MoveNewHyperplane(NewHyp, CurrentConstr, MovedHypGamma); // use MovedHypGamma as needed... QuoteI tried pointers like double** etc but I am continually getting |
Thomas
![]() CBuilder Developer |
2004-10-05 01:32:01 AM
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
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-10-05 01:58:44 AM
Re:accessing a delphi procedure from BCB project
"Thomas" < XXXX@XXXXX.COM >wrote in message
QuoteHere are parts of the code. 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 |
Thomas
![]() CBuilder Developer |
2004-10-05 04:41:30 AM
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
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-10-05 05:00:43 AM
Re:accessing a delphi procedure from BCB project
"Thomas" < XXXX@XXXXX.COM >wrote in message
QuoteI tried to find about DynamicArray class on the web and 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. QuoteIs it typical that one just studies the class definitions to QuoteAlso , if I have defined some C++ builder functions like this : DynamicArray where a raw array is expected because the memory layous are different. Gambit |