Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DelphiCode to C++Builder

38 views
Skip to first unread message

Sabetay Toros

unread,
Dec 10, 2001, 8:34:47 AM12/10/01
to
Hi,

This code snippet has been taken from Marko Cantu's Delphi Developer's
HandBook.

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyClass: TComponentClass;
MyComp: TComponent;
begin
MyClass := TComponentClass (GetClass (ComboBox1.Text));
if MyClass = nil then
Beep
else
begin
MyComp := MyClass.Create (self);
MyComp.Name := GetNextName (MyClass);
if MyClass.InheritsFrom (TControl) then
// if MyComp is TControl then // alternative version
begin
TControl (MyComp).Left := X;
TControl (MyComp).Top := Y;
TControl (MyComp).Parent := self;
end;
end;
UpdateList;
end;

MyComp := MyClass.Create (self);
I couldn't convert this line to C++ Code .
Does any body has any idea how this line will be convert to C++ Builder.
Thanks.
Sabetay


Russ Hore

unread,
Dec 10, 2001, 10:17:30 AM12/10/01
to
Please do not quote the whole message when replying.
Most of us I guess use threading newsreaders so we already have the old
message.


Rick Golden

unread,
Dec 10, 2001, 10:12:14 AM12/10/01
to
MyComp = new MyClass(this);

Sabetay Toros <bil...@superonline.com> wrote in message
news:3c14b991_1@dnews...

Remy Lebeau

unread,
Dec 10, 2001, 12:42:56 PM12/10/01
to
GetClass() returns a TMetaClass* in C++. C++ doesn't support creating new
class instances from their meta information like Delphi does, sorry. If you
want to use that code, you'll need to put it into it's own Delphi unit and
then include that unit into your C++ project (yes, you can mix Delphi and
C++ in the same project, Builder can compile both)


Gambit

"Sabetay Toros" <bil...@superonline.com> wrote in message
news:3c14b991_1@dnews...

Sabetay Toros

unread,
Dec 11, 2001, 3:27:47 AM12/11/01
to
Remy,

Thank you for your kind reply. That was exactly the answer that I was
waiting.
But I wonder, if there is any other different way to achieve this feature.
If not, my next question to the group is as follows: How can I mix
Delphi code with Builder? Where can I find information, help & examples?

Thanks,
Sabetay Toros
"Remy Lebeau" <gamb...@gte.net> wrote in message news:3c14f463$1_2@dnews...

Remy Lebeau

unread,
Dec 11, 2001, 12:32:39 PM12/11/01
to
"Sabetay Toros" <bil...@superonline.com> wrote in message
news:3c15c31b_2@dnews...

> But I wonder, if there is any other different way to achieve this
feature.

As I said, C++ doesn't support what you're trying to do, but Delphi does.

> How can I mix Delphi code with Builder?

As I said, simply put the code into its own unit and then add that Delphi
unit to your C++ project via "Add to Project". Builder will generate C++
header files for the Delphi code so that you can use them.


Gambit


Sabetay Toros

unread,
Dec 12, 2001, 5:24:26 AM12/12/01
to
I understand from that you will write the whole program in Delphi not in C++
Builder. This is not I want to do. Simply I want to write in Builder.
Let me put it the question in an another way. In C++Builder, instead of
creating specific instances of a given component, how can we write a generic
code that can create any kind of component ?
If we can not, can I implement a pascal function that will take ClassType
and this pointer, as arguments and then return a TComponent pointer. Is
it posible to write a pascal function and then call from C++ Builder ?

Thanks
"Remy Lebeau" <gamb...@gte.net> wrote in message news:3c16439f$4_2@dnews...

0 new messages