cpp >> Transcrypt code form delphi to C++Builder

by Didier » Wed, 18 Oct 2006 15:39:52 GMT

Hello
I want to use an object (imported from an wayx.ocx component ocx) in my
C++Builder
I have used it in delphi IDE without any problem but I can't find right
syntax to use it under C++Builder
For information this object calculate distance beetween two geographic
points
Here is the code under Delphi
var
myGeoAlgo: IOleGeoAlgo;

In my procedure
myGeoAlgo:= IOleGeoAlgo(CreateOleObject('WayX.GeoAlgo'));
myGeoAlgo.Lati1=41;
myGeoAlgo.longi1=5;
myGeoAlgo.Lati2=42;
myGeo.Algo.longi2=6
myGeoAlgo.Calculer();


So I've written under c++BUilder

IOleGeoObject *myGeoAlgo;
myGeoAlgo=IOleGeoAlgo(CreateOleObject("WayX.GeoAlgo"));

if i compile this I get the next error message at the compilation
[C++ Erreur] Unit1.cpp(23): E2352 Impossible de crr une instance de la
classe abstraite 'IOleGeoAlgo'
[C++ Erreur] Unit1.cpp(23): E2353 La classe 'IOleGeoAlgo' est abstraite
parce que '__stdcall IDispatch::GetTypeInfoCount(unsigned int *) = 0'

if I try
IOleGeoObject *myGeoAlgo;
myGeoAlgo.lati1=45.2
i get an error EAccesViolation

if I try
Variant toto;
toto = CreateOleObject("WayX.GeoAlgo");
toto.OlePropertySet("Lati1",45);
i get the same Acces violation at the run time

Can anybody help me to find the right syntax


IOleGeoAlgo *myGeoAlgo ;
toto = CreateOleObject("WayX.GeoAlgo");
toto.OlePropertySet("Lati1",12);






cpp >> Transcrypt code form delphi to C++Builder

by Duane Hebert » Wed, 18 Oct 2006 17:55:33 GMT






Don't know why it works in Delphi but...


The compiler is telling you that it's an abstract class.
At this point, let's assume that the compiler is correct.

This means that it has at least one pure virtual function.
A pure virtual function is declared as:
virtual type functionname = 0;
like:
virtual int doSomething() = 0;

The compiler is being nice and telling you that
IDispatch::GetTypeInfoCount() is pure virtual.
This implies that IOleGeoAlgo is derived from
IDispatch and that it hasn't implemented this
pure virtual function. This makes IOleGeoAlgo
abstract as well.

If IOleGeoAlgo is your class, you must implement
GetTypeInfoCount(). If it's not your class, you
need to subclass it and provide an implementation
there for this function.


Here, you're trying to use an unitialized
pointer. You need to instantiate myGeoAlgo.



Don't know what CreateOleObject() is or does.
Probably tries to create an instance of an object
and returns 0 on failure, but that's just a guess.






cpp >> Transcrypt code form delphi to C++Builder

by Remy Lebeau (TeamB) » Thu, 19 Oct 2006 00:43:44 GMT






Try this:

_di_IOleGeoAlgo myGeoAlgo;

myGeoAlgo = CreateOleObject("WayX.GeoAlgo");
myGeoAlgo->Lati1 = 41;
myGeoAlgo->longi1 = 5;
myGeoAlgo->Lati2 = 42;
myGeoAlgo->longi2 = 6
myGeoAlgo->Calculer();


Gambit




Transcrypt code form delphi to C++Builder

by Didier » Thu, 19 Oct 2006 14:25:45 GMT

I've tried it but the commpilation makes the next error on _di_IOle....
Symbol _di_IOle... not defined





Transcrypt code form delphi to C++Builder

by Remy Lebeau (TeamB) » Fri, 20 Oct 2006 01:09:34 GMT






Then you need to look in the .h file for the OCX to see what the wrapper
class is actually declared as. I might be IOleGeoAlgoPtr or
TCOMIOleGeoAlgoPtr or something like that. Look for a typedef that is using
either the DelphiInterface or TComInterface class.


Gambit




Transcrypt code form delphi to C++Builder

by Muzaffar Mahkamov » Sat, 21 Oct 2006 03:17:15 GMT





Shouldn't it be:

IOleGeoObject *myGeoAlgo;
myGeoAlgo=(IOleGeoAlgo*)CreateOleObject("WayX.GeoAlgo");

In your code you're trying to create an object of IOleGeoAlgo class
which is not possible because it's an interface, usually with pure
virtual methods.


Transcrypt code form delphi to C++Builder

by Remy Lebeau (TeamB) » Sat, 21 Oct 2006 04:51:14 GMT






That would not work. CreateOleObject() returns a _di_IDispatch, which will
not know how to be casted to a IOleGeoAlgo* directly. You must call the
IDispatch's QueryInterface() method (either directly or indirectly) in order
to cast an interface pointer from one type to another safely.


Gambit




Similar Threads

1. dynamic code, change code in cs

How is this possible:

  mov  DWORD PTR CS:[@cleanstack+2],0
  //.......
  call [pMethodAddr]
@cleanstack:
  add  ESP, DWORD(1)
    // this instruction can be changed
    // by the stack-cleanup setup depending
    // on CpuHelper.boCleanESP (for cdecl function)

for the moment i always get an AV at the mov
statement. I think i don't have the permission
from the os to write to the Codesegent at this
address. How can I change this?

TIA
Guenther


2. linking .cs form to .aspx form using C# - CSharp/C#

3. Newbie: Should code go in Form.cs or FormDesigner.cs?

There are situations where it appears code can go either in the form 
Designer's class or the form's class.  Is there a best practice regarding 
where code should go?  Does it matter?

Here are some examples:

1)  If I have multiple TreeViews on a single form (Form1) and I want to 
consolidate all the code necessary to build the various ImageLists.  Should 
I put this code in Form1Designer.cs or Form1.cs?

2)  If I have different non-visible components on a form (e.g. Timer, etc.) 
should the component initialization code go in the Designer or the form, or 
in the form itself - perhaps in the constructor or FormLoad event?

3) If I have multiple derived controls on a form, should the initialization 
code for these controls be in the parent form's Designer or in each derived 
control's class?

When should code go in the Designer and when in the object's class?

Are there advantages/disadvantages of each option?

Thanks in advance.


4. Calling a C++ Form from a Delphi Form

5. Calling a C++ Form from a Delphi Form [solved]

Remy Lebeau (TeamB) wrote:
Thanks for the quick response.

> What is the exact linker error?  You need to be more specific.
I needed extern "C" for the delphi side to see it. (solved).
> 
>> TForm *GetTForm1() { if (Form1==0) Form1 = new TForm1(Form1);
>> return Form1;

I read that Delphi has everything by reference so it's changed to:
TForm & WINAPI _export GetTForm1() {

	if (Form1==0)  Application->CreateForm(__classid(TForm1), &Form1);
	 return *Form1;
	}
}


> 
> You are passing the NULLified Form1 pointer as the Owner of the TForm1 
> instance you are trying to create for the Form1 pointer.  If you don't want 
> the new form to have an Owner, then specify NULL explicitally instead:
> 
>     TForm *GetTForm1()
>     {
>         if (Form1==NULL)
>             Form1 = new TForm1(NULL);
>         return Form1;
>     }

Not the intent in this case, once the form is created it shouldn't go 
away so it's owner should be the application. However this is good to 
know anyways.


> Now, with that said - I would suggest moving the body of GetTForm() into the 
> form's .cpp file instead of having it inlined in the header file:

OK, done.

new code is (inside unit1.cpp)

extern "C" {

TForm & WINAPI _export GetTForm1() {

	if (Form1==0)  Application->CreateForm(__classid(TForm1), &Form1);
	 return *Form1;
	}
}


Thanks for your help!

6. How to rewrite in C++ Code from Delphi Code - Borland C++ Builder VCL Components

7. Taking a single large .cs file and making many smaller .cs files

"Greg Larsen" < XXXX@XXXXX.COM > ha scritto nel messaggio 
news:79450CE7-E6E2-43E8-8FD9-

> If I'm building a class as ABC, and in contains a lot of methods, 
> eventually
> my code file ABC.cs get extremely large, let say 3000+ lines of code. 
> What
> are the best approaches to breaking up my large ABC.cs file into smaller
> manageable chunks, so no code file is larger that say 200-300 lines of 
> code?

best: Restructure the code and using more specific classes.

worse: use the "partial" keyword.



8. Calling the function in one cs from another cs file - CSharp/C#