VCL 转 OCX 的问题(100分)

C

cyy

Unregistered / Unconfirmed
GUEST, unregistred user!
我与朋友共同开发软件,我用 D4,他用 VB,由于 D4 下有许多
不错的免费 VCL 希望将其继承下来制成 OCX,而且有些也的确成功了
(如 RX CONTROL 中的 RXCLOCK),但有些控件却不行,它们根本就
不出现在Activex Control Wizard 的 VCL Class Name 列表中,
无法继承。
请问:
1.什么样的 VCL 才能创建 OCX ?(有些又有些没有,什么
道理?要转 OCX,VCL 需要满足什么条件?)
2.如何修改带源码的VCL,使其能创建 OCX ?
或者说:这类 VCL 怎样才能创建 OCX ? 希望各位大哥提点!
(最好有些代码例子可以说明)
再次谢过!谢谢!谢谢!:)
 
H

huizhang

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi's ActiveX Control Wizard can only convert a Windowed VCL control
to a ActiveX Control. That means TGraphicControl and TComponent, such
as TImage, TBevel, TOpenDialog..., can not be converted to a ActiveX
Control by the Wizard directly.
If you want to make a ActiveX Control out of a TGraphicControl, you
can use a TWinControl as a GraphicControl container, and bind all the
graphic properties and method to that WinControl. After you havedo
ne
that and registered the new control, you can use the wizard to convert
it to a ActiveX Control.
For example:
Type
TWinImage = class(tpanel)
private
fImage: TImage;
function GetPicture: TPicture;
procedure SetPicture(value: TPicture);
function GetStretch: boolean;
procedure SetStretch(value: boolean);
public
constructor Create(AOwner: TComponent);
destructor Destroy;
procedure LoadFromFile(FileName: String);
published
property Picture: TPicture read GetPicture write SetPicture;
property Stretch: Boolean read GetStredth write SetStretch;
end;
...
implimentation
constructor TWinImage.Create(AOwner: TComponent);
begin
inherited;
fImage := TImage.Create(self);
fImage.Align := alClient;
fImage.Parent := Self;
end;
function TWinImage.GetPicture: TPicture;
begin
result := fImage.Picture;
end;
procedure TWinImage.SetPicture(value: TPicture);
begin
fImage.Picture := value;
end;
function TWinImage.GetStretch: boolean;
begin
result := fImage.Stretch;
end;
procedure TWinImage.SetStretch(value: boolean);
begin
fImage.Stretch := value;
end;
destructor TWinImage.Destroy;
begin
fImage.free;
inherited;
end;

An alternate way todo
this is to inherit a TWinControl and add Graphic
capabilities to it. A good example is TStaticText.
 
C

cyy

Unregistered / Unconfirmed
GUEST, unregistred user!
huizhang:
您的方法在有源码的时候很管用,但是如果源VCL没有源码,处理起来就不行了,
DELPHI会出错误提示。这时是不是就没有办法了?我想,在TPanel中运行一个实例,
并建立所有的参数传递,应该可以不用源VCL的源码的吧?还请您再次提点!谢谢!
 
J

Jams

Unregistered / Unconfirmed
GUEST, unregistred user!
使用DLL调用VCL能行!DLL比OCX要好。
 
H

huizhang

Unregistered / Unconfirmed
GUEST, unregistred user!
没有源码你也可以调用它的方法, 封装成OCX
 
C

cyy

Unregistered / Unconfirmed
GUEST, unregistred user!
感谢 huizhang 和 Jams 我的问题已经解决,方法和 huizhang 的差不多(还是
您的注意)只是需要单独添加一个事件来运行VCL实例,否则Delphi总要提示没有源VCL
的PAS文件,不知为什么.
其实做成DLL也挺好的,只是在调用时稍微麻烦些(我那朋友对VB不是很熟).
现在发工资,huizhang:90 Jams:10 大家没有意见吧!
 
C

cyy

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
顶部