D
dream
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟通过继承tcustomcom做了一个选择线壮符号的控件tmylinecombobox。
想把这个控件生成Activex控件,可在activex control wizard
加入tmylinecombobox类时,却出现“ control '' has no parent window”这错误。
有哪位大虾能指点迷津,谢了!!!
tmylinecombobox 的原码如下:
unit mylinestyle;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
tmylinecombobox = class(TCustomComboBox)
private
{ Private declarations}
plinestyle : integer;
procedure DrawPen(Control: TWinControl
Index: Integer
Rect: TRect;
State: TOwnerDrawState);
protected
{ Protected declarations }
public
{ Public declarations }
LineList :array[0..4] of integer;
Changed : Boolean;
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
procedure DoChange(Sender : TObject);
published
{ Published declarations }
property linestyle : integer read plinestyle write plinestyle;
property OnChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyControl', [TmyLineComboBox]);
end;
procedure tmylinecombobox.DrawPen(Control: TWinControl
Index: Integer
Rect: TRect;
State: TOwnerDrawState);
begin
with Canvas do begin
brush.Style:=bsclear;
brush.color:=clwhite;
pen.color:=clwhite;
Rectangle(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom);
pen.Style := TpenStyle(lineList[Index]);
pen.color:=clblack;
MoveTo(Rect.Left+15,Rect.Top+Trunc(ItemHeight/2));
LineTo(Rect.Right-15,Rect.Top+Trunc(ItemHeight/2));
end;
end;
constructor tmylinecombobox.Create(AOwner: TComponent);
var
I : integer;
begin
inherited Create(AOwner);
Parent := TForm(AOwner);
OnDrawItem := DrawPen;
OnChange := DoChange;
for I := 0 to 4 do Items.Add('');
LineList[0]:= 0;
LineList[1]:= 1;
LineList[2]:= 2;
LineList[3]:= 3;
linelist[4]:=4;
Style := csOwnerDrawFixed;
itemindex:=0;
end;
destructor tmylinecombobox.Destroy;
begin
inherited Destroy;
end;
procedure tmylinecombobox.DoChange(Sender : TObject);
begin
linestyle := LineList[Self.ItemIndex];
Changed := TRUE;
end;
end.