Home > Back-end >  Be urgent!!!!!! How can create the container with ActiveX control
Be urgent!!!!!! How can create the container with ActiveX control

Time:10-19

Ask a question: how can create the container with the DELPHI (other activex controls can be placed inside) activex control, is used as a container like a Panel.

Directly from TPanel TScrollBox create ActiveX control doesn't work, not when a container.

CodePudding user response:

1. The main...

 unit DynamicOleControl; 


Interface


USES Windows, Classes, ActiveX, OleCtrls ComObj;


Type
TDynamicOleControl=class (TOleControl)
Private
FClassID: TGUID;
FIntf: IUnknown;


The function GetControlInterface: IUnknown;
Protected
Procedure CreateControl;
Procedure InitControlData; Override.
Public
The constructor CreateFromClassID (AOwner: TComponent; AClassID: TGUID); The phrase ";
The constructor CreateFromClassID (AOwner: TComponent; AClassID: string); The phrase ";
The constructor CreateFromProgID (AOwner: TComponent; AProgID: string);


The property ControlInterface: IUnknown read GetControlInterface;
The property DefaultInterface: IUnknown read GetControlInterface;


Published
The property Anchors;
end;


Implementation


The constructor TDynamicOleControl. CreateFromClassID (AOwner: TComponent;
AClassID: TGUID);
The begin
FClassID:=AClassID;


Inherited the Create (AOwner);
end;


The constructor TDynamicOleControl. CreateFromClassID (AOwner: TComponent; AClassID: string);
The begin
FClassID:=StringToGUID (AClassID);
Inherited the Create (AOwner);
end;


The constructor TDynamicOleControl. CreateFromProgID (AOwner: TComponent;
AProgID: string);
The begin
FClassID:=ProgIDToClassID (AProgID);
Inherited the Create (AOwner);
end;


Procedure TDynamicOleControl. InitControlData;
Const
CControlData: TControlData2=(
Every: "';
EventIID: "';
EventCount: 0;
LicenseKey: nil;
Flags: $00000000;//$0000001 d
Version: 401
);
The begin
CopyMemory (@ CControlData. Every @ FClassID, SizeOf (TGUID));
ControlData:=@ CControlData;
end;


Procedure TDynamicOleControl. CreateControl;


Procedure DoCreate;
The begin
FIntf:=IUnknown (OleObject) as IUnknown;
end;


The begin
If FIntf=nil then DoCreate;
end;


The function TDynamicOleControl. GetControlInterface: IUnknown;
The begin
CreateControl;
Result:=FIntf;
end;


End.

CodePudding user response:

2. DynamicOleControl. Pas...

 unit MainUnit; 


Interface


USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DynamicOleControl StdCtrls, Buttons, ExtCtrls, ComObj;


Type
TMainForm=class (TForm)
Pnl1: TPanel;
PnlContainer: TPanel;
Lbl1: TLabel;
EdtClassID: TEdit;
BtnLoad: TBitBtn;
BtnFree: TBitBtn;
Label1: TLabel;
EdtProgID: TEdit;
Label2: TLabel;
Procedure btnFreeClick (Sender: TObject);
Procedure btnLoadClick (Sender: TObject);
Procedure FormClose (Sender: TObject; Var Action: TCloseAction);
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
FMyOleControl: TDynamicOleControl;


Procedure FreeOleControl;
Public
{Public declarations}
end;


Var
MainForm: TMainForm;


Implementation


{$R *. DFM}

Procedure TMainForm. FormCreate (Sender: TObject);
The begin
FMyOleControl:=nil;
end;


Procedure TMainForm. FormClose (Sender: TObject; Var Action: TCloseAction);
The begin
FreeOleControl;
end;


Procedure TMainForm. FreeOleControl;
The begin
If Assigned (FMyOleControl) then
FreeAndNil (FMyOleControl);
end;


Procedure TMainForm. BtnFreeClick (Sender: TObject);
The begin
FreeOleControl;
end;


Procedure TMainForm. BtnLoadClick (Sender: TObject);
The begin
FreeOleControl;


Try
If the Trim (edtClassID. Text) & lt; & gt; "' then
FMyOleControl:=TDynamicOleControl CreateFromClassID (Self,
Trim (edtClassID. Text))
Else if the Trim (edtProgID. Text) & lt; & gt; "' then
FMyOleControl:=TDynamicOleControl CreateFromProgID (Self,
Trim (edtProgID. Text));


If Assigned (FMyOleControl) then
The begin
PnlContainer. InsertControl (FMyOleControl);
FMyOleControl. Align:=alClient;
end;
Except,
On e: EOleSysError do
Application. MessageBox (PChar (e.M essage), 'mistakes', MB_OK + MB_ICONERROR);
end;
end;


End.


CodePudding user response:

3. Try to run, activex components can be displayed in the form; Can specify the Parent, if necessary, to encapsulate the event or methods of dynamic loading,,,,

CodePudding user response:

Thank you, boss can also copy the code DFM file:)nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related