Board index » cppbuilder » CoClass Pointer or Pointer to ActiveForm GUI

CoClass Pointer or Pointer to ActiveForm GUI

Still no luck on getting a pointer to the CoClass of my BCB 4.0 ActiveX Form
from the ActiveX wrapper generated by MSVC++ 6.0.
One posting hinted at a GetObjectPointer function in the MSVC++ wrapper
class for the interface, but as far as I can tell this does not exist.
I have searched the www.deja.com address I was given by Alex Bakaev of
[TeamB] but found nothing that helps.  Has anyone out there done this
before?

Please help! (I hope that sounded pathetic.)

 

Re:CoClass Pointer or Pointer to ActiveForm GUI


Paul, now I'm confused. What are you trying to do ? When VC generates a
wrapper, don't you get the whole access to the interfaces of an ActiveX
?

Alex

Quote
Paul Lewis wrote:

[snip]

Re:CoClass Pointer or Pointer to ActiveForm GUI


Yes.  I do get access to all the functions in the interface, but I do not
get a pointer to the ActiveX Form itself.  So for instance if i have 5
controls (TButton for instance) on my form and I want to be able to access
each of their Enabled, Visible, Caption, and Hint properties I would have to
add methods to the interface for each of them.  -- Get and Get (2) for each
Enabled, Visible, Caption, and Hint (4)  for each of the buttons (5).  2 X 4
X 5 is 40 functions.  Thats a lot of functions I would have to write,
considering some of my forms have upwards of 40 components on them this
would tae quite a while.  What would be better is if I could have access to
the m_VclCtl variable or a pointer to the coClass itsself from Visual C++ so
I could access those properties directly without having to write all the
interface functions myself.  Can this be done?

Alex Bakaev [TeamB] <al...@jetsuite.com> wrote in message
<news:37A72DFC.1864EA7B@jetsuite.com>...

Quote
> Paul, now I'm confused. What are you trying to do ? When VC generates a
> wrapper, don't you get the whole access to the interfaces of an ActiveX
> ?

> Alex

Re:CoClass Pointer or Pointer to ActiveForm GUI


Paul, you could define a method/property that returns the m_VclCtl. But
this will be useless in VC++. If may define one big mother of a
structure that defines states of all objects on the form and use that to
set states of all the objects in single call.

Alex

Quote
Paul Lewis wrote:

[snip]

--
HotSend - portable documents technology
http://www.hotsend.com/
eFax - get your faxes via email - Free !
http://www.efax.com

Re:CoClass Pointer or Pointer to ActiveForm GUI


Cool!   Don't know if this is exactly what you were saying, but after
reading your message I came up with the following idea.  I added a function
to the interface that took 3 BSTR's as inputs.  The first was a
componentName, the second the Property I wanted to access and the third was
the value I wanted to assign to the Property.  I then added the following
Code to my new interface method. (Long and ugly, but it works!)

STDMETHODIMP TPaulActiveXImpl::setComponentProperty(BSTR ComponentName,
  BSTR Property, BSTR Value)
{
  try
  {
     bool success = false;
     String compName ;

     String property = AnsiString(Property);
     String value = AnsiString(Value);
     String componentName = AnsiString(ComponentName);

     int numControls = m_VclCtl->ComponentCount;
     //  Loop through the controls on the form.
     for(int index=0; index< numControls; index++)
     {
          compName = m_VclCtl->Components[index]->Name;
          //   Find the one with the correct name
          if(compName == componentName)
          {
               //  Get a pointer to the component
               TComponent* component =  m_VclCtl->Components[index];

               //  TMenuITem is the only control that I use that is a
TComponent.
               //  All others have  methods that are implemented in
TControl.
               //  This is a special case.
               if(component->ClassNameIs("TMenuITem"))
               {
                    //  Get a pointer to the TMenuItem
                    TMenuItem* menuItem = (TMenuItem*)component;

                    //  If we are setting the Caption...
                    if(property == "Caption")
                    {
                         menuItem->Caption = value;
                         success = true;
                    }
                    //  If we are setting the Hint...
                    else if(property == "ToolTip")
                    {
                         menuItem->Hint = value;
                         success = true;
                    }
                    //  If we are setting the Enabled property...
                    else if(property == "Enabled")
                    {
                         bool boolValue = false;
                         if(value == "true")
                              boolValue = true;

                         menuItem->Enabled = boolValue;
                         success = true;
                    }
                    //  If we are setting the Visible property...
                    else if(property == "Visible")
                    {
                         bool boolValue = false;
                         if(value == "true")
                              boolValue = true;

                         menuItem->Visible = boolValue;
                         success = true;
                    }
               }
               //  If it is not a TMenuITem then the component must derive
from
               //  TControl, so instead of figuring out what it is I will be
               //  lazy and just cast it to a TControl* and then set the
               //  appropriate property.
               else
               {
                    //  We'll check just to makeSure...
                    if(component->InheritsFrom(__classid(TControl)))
                    {
                         //  Get a TControl pointer to the component.
                         TControl* control = (TControl*)component;

                         //  If we are setting the Caption...
                         if(property == "Caption")
                         {
                              //  **  The Caption of a component is
protected at the TControl level
                              //  **  (not all components have Captions), so
we must determine the actual
                              //  **  class we are dealing with, cast the
TComponent to that class, and
                              //  **  set the correct property for the
class.

                              //  TMenuButton
                              if(control->ClassNameIs("TMenuButton"))
                              {
                                   TMenuButton* temp = (TMenuButton*)
control;
                                   temp->Caption = value;
                                   success = true;
                              }

                              //  TSpeedButton
                              else if(control->ClassNameIs("TSpeedButton"))
                              {
                                   TSpeedButton* temp = (TSpeedButton*)
control;
                                   temp->Caption = value;
                                   success = true;
                              }

                              //  TButton
                              else if(control->ClassNameIs("TButton"))
                              {
                                   TButton* temp = (TButton*) control;
                                   temp->Caption = value;
                                   success = true;
                              }

                              //  TLabel
                              else if(control->ClassNameIs("TLabel"))
                              {
                                   TLabel* temp = (TLabel*) control;
                                   temp->Caption = value;
                                   success = true;
                              }
                              //  Unsupported component type
                              else
                              {
                                   //  Do nothing
                              }

                         }
                         //  If we are setting the Hint...
                         else if(property == "ToolTip")
                         {
                              control->Hint = value;
                              success = true;
                         }
                         //  If we are setting the Enabled property...
                         else if(property == "Enabled")
                         {
                              bool boolValue = false;
                              if(value == "true")
                                   boolValue = true;

                              control->Enabled = boolValue;
                              success = true;
                         }
                         //  If we are setting the Visible property...
                         else if(property == "Visible")
                         {
                              bool boolValue = false;
                              if(value == "true")
                                   boolValue = true;

                              control->Visible = boolValue;
                              success = true;
                         }
                    } // end ifInherits from(TControl)
                    else
                    {
                         //  Do nothing for the time being.
                    }
               } // end else
          } // end if (compName == ComponentName)
     }//  end of the for loop

   if(!success)
     return S_FALSE;

  }
  catch(Exception &e)
  {
    return Error(e.Message.c_str(), IID_IPaulActiveX);
  }
  return S_OK;

Quote
};

Now I can set the Properties for objects that I need to and I only have to
add one function to each ActiveX Form.  And I can cut and paste that! Or
possibly inherit it.

Of course I will add more properties to my function and maybe add another
function or two that returns all the names of the components and such, but
it looks like this will help significantly.

Could something like this be an enhancement for future versions of BCB?

Thanks for all your timely and appropriate help!  You have saved me some
serious time.

Thanks again,

Paul Lewis

Alex Bakaev [TeamB] <al...@jetsuite.com> wrote in message
news:37A7464A.DCE4ACBB@jetsuite.com...

Quote
> Paul, you could define a method/property that returns the m_VclCtl. But
> this will be useless in VC++. If may define one big mother of a
> structure that defines states of all objects on the form and use that to
> set states of all the objects in single call.

> Alex

Re:CoClass Pointer or Pointer to ActiveForm GUI


Paul, glad you found a solution; this certainly is a good approach. One
thing you could add, if needed is a query function that will return all
possible names of a component and tha range of values for each. You
could use this in a UI, if needed.

Cheers,
Alex

Quote
Paul Lewis wrote:

[snip]

--
HotSend - portable documents technology
http://www.hotsend.com/
eFax - get your faxes via email - Free !
http://www.efax.com

Re:CoClass Pointer or Pointer to ActiveForm GUI


This is the right way to do it. If you need to expose something through COM,
especially for "contained" components, you will need to create extra
methods/properties/sub-property interfaces to provide access to COM clients.

have fun
--
Binh Ly
http://www.castle.net/~bly/Programming/Delphi

Quote
Paul Lewis <sl...@cc.usu.edu> wrote in message

news:7o7nlk$n5o6@forums.borland.com...
Quote
> Cool!   Don't know if this is exactly what you were saying, but after
> reading your message I came up with the following idea.  I added a
function
> to the interface that took 3 BSTR's as inputs.  The first was a
> componentName, the second the Property I wanted to access and the third
was
> the value I wanted to assign to the Property.  I then added the following
> Code to my new interface method. (Long and ugly, but it works!)

> STDMETHODIMP TPaulActiveXImpl::setComponentProperty(BSTR ComponentName,
>   BSTR Property, BSTR Value)
> {
>   try
>   {
>      bool success = false;
>      String compName ;

>      String property = AnsiString(Property);
>      String value = AnsiString(Value);
>      String componentName = AnsiString(ComponentName);

>      int numControls = m_VclCtl->ComponentCount;
>      //  Loop through the controls on the form.
>      for(int index=0; index< numControls; index++)
>      {
>           compName = m_VclCtl->Components[index]->Name;
>           //   Find the one with the correct name
>           if(compName == componentName)
>           {
>                //  Get a pointer to the component
>                TComponent* component =  m_VclCtl->Components[index];

>                //  TMenuITem is the only control that I use that is a
> TComponent.
>                //  All others have  methods that are implemented in
> TControl.
>                //  This is a special case.
>                if(component->ClassNameIs("TMenuITem"))
>                {
>                     //  Get a pointer to the TMenuItem
>                     TMenuItem* menuItem = (TMenuItem*)component;

>                     //  If we are setting the Caption...
>                     if(property == "Caption")
>                     {
>                          menuItem->Caption = value;
>                          success = true;
>                     }
>                     //  If we are setting the Hint...
>                     else if(property == "ToolTip")
>                     {
>                          menuItem->Hint = value;
>                          success = true;
>                     }
>                     //  If we are setting the Enabled property...
>                     else if(property == "Enabled")
>                     {
>                          bool boolValue = false;
>                          if(value == "true")
>                               boolValue = true;

>                          menuItem->Enabled = boolValue;
>                          success = true;
>                     }
>                     //  If we are setting the Visible property...
>                     else if(property == "Visible")
>                     {
>                          bool boolValue = false;
>                          if(value == "true")
>                               boolValue = true;

>                          menuItem->Visible = boolValue;
>                          success = true;
>                     }
>                }
>                //  If it is not a TMenuITem then the component must derive
> from
>                //  TControl, so instead of figuring out what it is I will
be
>                //  lazy and just cast it to a TControl* and then set the
>                //  appropriate property.
>                else
>                {
>                     //  We'll check just to makeSure...
>                     if(component->InheritsFrom(__classid(TControl)))
>                     {
>                          //  Get a TControl pointer to the component.
>                          TControl* control = (TControl*)component;

>                          //  If we are setting the Caption...
>                          if(property == "Caption")
>                          {
>                               //  **  The Caption of a component is
> protected at the TControl level
>                               //  **  (not all components have Captions),
so
> we must determine the actual
>                               //  **  class we are dealing with, cast the
> TComponent to that class, and
>                               //  **  set the correct property for the
> class.

>                               //  TMenuButton
>                               if(control->ClassNameIs("TMenuButton"))
>                               {
>                                    TMenuButton* temp = (TMenuButton*)
> control;
>                                    temp->Caption = value;
>                                    success = true;
>                               }

>                               //  TSpeedButton
>                               else

if(control->ClassNameIs("TSpeedButton"))

- Show quoted text -

Quote
>                               {
>                                    TSpeedButton* temp = (TSpeedButton*)
> control;
>                                    temp->Caption = value;
>                                    success = true;
>                               }

>                               //  TButton
>                               else if(control->ClassNameIs("TButton"))
>                               {
>                                    TButton* temp = (TButton*) control;
>                                    temp->Caption = value;
>                                    success = true;
>                               }

>                               //  TLabel
>                               else if(control->ClassNameIs("TLabel"))
>                               {
>                                    TLabel* temp = (TLabel*) control;
>                                    temp->Caption = value;
>                                    success = true;
>                               }
>                               //  Unsupported component type
>                               else
>                               {
>                                    //  Do nothing
>                               }

>                          }
>                          //  If we are setting the Hint...
>                          else if(property == "ToolTip")
>                          {
>                               control->Hint = value;
>                               success = true;
>                          }
>                          //  If we are setting the Enabled property...
>                          else if(property == "Enabled")
>                          {
>                               bool boolValue = false;
>                               if(value == "true")
>                                    boolValue = true;

>                               control->Enabled = boolValue;
>                               success = true;
>                          }
>                          //  If we are setting the Visible property...
>                          else if(property == "Visible")
>                          {
>                               bool boolValue = false;
>                               if(value == "true")
>                                    boolValue = true;

>                               control->Visible = boolValue;
>                               success = true;
>                          }
>                     } // end ifInherits from(TControl)
>                     else
>                     {
>                          //  Do nothing for the time being.
>                     }
>                } // end else
>           } // end if (compName == ComponentName)
>      }//  end of the for loop

>    if(!success)
>      return S_FALSE;

>   }
>   catch(Exception &e)
>   {
>     return Error(e.Message.c_str(), IID_IPaulActiveX);
>   }
>   return S_OK;
> };

> Now I can set the Properties for objects that I need to and I only have to
> add one function to each ActiveX Form.  And I can cut and paste that! Or
> possibly inherit it.

> Of course I will add more properties to my function and maybe add another
> function or two that returns all the names of the components and such, but
> it looks like this will help significantly.

> Could something like this be an enhancement for future versions of BCB?

> Thanks for all your timely and appropriate help!  You have saved me some
> serious time.

> Thanks again,

> Paul Lewis

> Alex Bakaev [TeamB] <al...@jetsuite.com> wrote in message
> news:37A7464A.DCE4ACBB@jetsuite.com...
> > Paul, you could define a method/property that returns the m_VclCtl. But
> > this will be useless in VC++. If may define one big mother of a
> > structure that defines states of all objects on the form and use that to
> > set states of all the objects in single call.

> > Alex

Other Threads