tags:

views:

109

answers:

1

You can publish the properties of an control that is inside a activex form?

example I have a form with an TAdoconnection component, I wish the properties of this component can be modified by the user when he loads my activex control.

alt text

UPDATE

@TOndrej gives me a very nice sample, but this sample only works for components derived from an activex control, how can accomplish this same efffect with an VCL component like an Timage or TMemo? is possible publish all the properties without rewrite each property to expose manually?

+3  A: 

ADO components are already ActiveX objects, so the easiest way is to expose the connection as a simple property of your ActiveX form:

In the type library editor, add "Microsoft ActiveX Data Objects 2.1 Library" to the list of used libraries. This will generate ADODB_TLB.pas unit in your project directory.

alt text

Then you can declare a new read-only property Connection of type Connection (this type is declared in ADODB_TLB unit) in your IActiveFormX interface.

alt text

In the implementation, you can simply return the interface from your TADOConnection component:

type
  THackADOConnection = class(TADOConnection);

function TActiveFormX.Get_Connection: Connection;
begin
  Result := Connection(THackADOConnection(ADOConnection).ConnectionObject);
end;

The THackADOConnection typecast is only necessary because ConnectionObject is protected. The outer Connection typecast is there to get rid of the compiler error "Incompatible types: ADODB_TLB._Connection and ADOInt._Connection."

TOndrej
@TOndrej, thanks very much for you recomendation, this work for components derived from an activex, but how can this with an VCL component like an timage or tmemo?
Salvador
You can write another interface exposing the component's methods and properties, declare a property of that type on your active form, and write an implementation delegating the calls to your underlying component.
TOndrej