cpp >> Calling a C++ Form from a Delphi Form [solved]

by Chris Bruner » Thu, 07 Aug 2008 03:46:37 GMT

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!


cpp >> Calling a C++ Form from a Delphi Form [solved]

by Remy Lebeau (TeamB) » Thu, 07 Aug 2008 03:53:45 GMT







Then you read wrong.


change it back to use pointers as before. That is what Delphi is actually
expecting.


Gambit





cpp >> Calling a C++ Form from a Delphi Form [solved]

by Chris Bruner » Thu, 07 Aug 2008 04:26:49 GMT





From Delphi:
function GetIfcaRiaForm(): TForm; stdcall far; external 'dll123.dll';

called using:

GetIfcaRiaForm.ShowModal;


From C++:

extern "C" {

TForm & WINAPI _export GetIfcaRiaForm() {

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

}


Seems to work.



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

by Remy Lebeau (TeamB) » Thu, 07 Aug 2008 05:54:24 GMT






That is using a pointer, not a reference. Object variables in Delphi are
pointers. The equivilent to that declaration in C++ is this:

TForm* __stdcall GetIfcaRiaForm();


Which would be this in C++:

GetIfcaRiaForm()->ShowModal();


That is wrong. This is what you need:

extern "C"
{
TForm* WINAPI _export GetIfcaRiaForm()
{
if( IfcaRiaForm == NULL )
Application->CreateForm(__classid(TIfcaRiaForm),
&IfcaRiaForm);
return IfcaRiaForm;
}
}


But is wrong.


Gambit




Similar Threads

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

I'm getting lost in my classes and need to simplify. The biggest 
simplification would be to remove delphi and just use C++, but I want to 
do this a step (form) at a time.

My idea is to use dynamic creation of forms and call from the Delphi form.


That is, where the form would be dynamically created in Delphi

(for example).

function frmIFCAOptions : TfrmIFCAOptions;
begin
   if (FfrmIFCAOptions = nil) then
     Application.CreateForm(TfrmIFCAOptions,FfrmIFCAOptions);
   if (FfrmIFCAOptions = nil) then
     NoResourcesException;

   Result := FfrmIFCAOptions;
end;

This function will create the form if needed and return the form once 
created.  (This tecnique can save a ton of memory for seldom used forms).


How would I do this with CBuilder forms, where I would create a Cbuilder 
form as needed.

I was thinking of something like this, but the linker can't seem to find it.


class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TLabel *Label1;
	TButton *Button1;
	void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
TForm *GetTForm1() { if (Form1==0) Form1 = new TForm1(Form1);
					 return Form1;
					}

2. Call a form form a form - CSharp/C#

3. form calling a form question

Hi,

I've a main Window form, which sometimes calls a new form, with a textBox 
and a ok button. (I'm trying to make it to look and feel like a MessageBox).

My problem is that when i'm minimizing the main window, and then maximizing 
it, the messgeBox form is not shown (i need to open it from the explorer 
bar). How can I make it to be a a part of the form? 

I need something like ShowDialog which will make my mainForm to wait for the 
MessageBox form will be closed in order to continue.

Thanks,
Gidi.

4. Form call Form => .exe - CSharp/C#

5. calling a form from a form

hi !  i've recently begun developing in c# and i'd like to know what's the 
best way of calling a form from an already instanced form ?  I have done a 
"Login" form which I run in the Main() using "Application.Run(...)", now when 
the user logins correctly, another form named "Calendar" must be called.  How 
can I do this ?  Should I close the first form first and then instance the 
new one or how ?  Thanks.

6. How to call an event on another form - C# windows forms - CSharp/C#

7. Calling inherited form - form loads and is a creature somewhat

Thank you for your response.  The reason I am inheriting is because I want to 
be able to access a variable that I am using in the other class.  Is there 
another way to make the variable in class A visible to class B?  Thank you.



"Michael C" wrote:

> "nidget" < XXXX@XXXXX.COM > wrote in message 
> news: XXXX@XXXXX.COM ...
> >I don't know what I am doing wrong - I have two forms, I will call them A 
> >and
> > B.  B is a class inherted from A.  I am calling B from A with 
> > B.ShowDialog().
> > When B loads, it is a creature somewhat like the first form and the form 
> > it
> > should be.  Some of the controls from A are now on B and fully functional.
> > Why are they showing up on my new form?  It only seems to happen when B is
> > inherited from A.  Hope this isn't confusing.  Thank you.
> 
> This is what is meant to happen. You chose to inherit from A so B gets the 
> controls of A. Why did you inherit from A?
> 
> Michael 
> 
> 
> 

8. Call an event handler on a parent form from child form - CSharp/C#