control '' has no parent window, 在线等待(100分)

  • 主题发起人 主题发起人 zzutrain
  • 开始时间 开始时间
Z

zzutrain

Unregistered / Unconfirmed
GUEST, unregistred user!
我自己写了几个控件,发现只要是 class(TCustomControl)的控件都存在这样的问题,请
各位给点帮助。说明错误原因,如何解决?
 
没有人可以解决么?
 
瞎主意:
你看看DELPHI本生还有什么控件继承自TCustomControl,然后再看看他还有什么
特别的什么方法之类的。
 
constructor TMoveMemo.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fStep:=50;
fStay:=3000;
fWait:=5000;
fBgColor:=clBlack;
fStayTimer:=Nil;
fTimer:=Nil;
fActive:=False;
fTimerTag:=False;
Drawing:=False;
OffScreen:=TBitMap.Create;

Width:=200;
Height:=200;
//////////////////////////////
Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
end;

请问是不是因为使用了self ,如果不能用,请各位帮忙改改!谢谢
 
应该是这个吧!因为一个控件的父主见要负责控件的显示的!
你把这句Memo:=TRxRichEdit.Create(Self);
改成Memo.Parent:=GetParentComponent;
看看!
 
不可以。
 
为什么?如果是编译通不过的话改成
Memo.Parent:=TWinControl(GetParentComponent);
事事!!
 
还是 control '' has not parent window
 
在create构造函数中是不能将别的控件的parent指向它自己的,因为连它自己都没有构造完
好像应该是应该重载wndcreate这个函数(我记不清楚了)
你可以查查mastering delphi6.0上面对这种情况作了特别的说明,也有一个具体的例子
 
能不能把代码发来看看??
 
Memo:=TRxRichEdit.Create(TWinControl(GetParentComponent));

也不可以。

在程序员大本营中Delphi ,Pb B碟中有个Viewer控件,使用了上述方法。

Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
 
unit MoveMemo;

interface

Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls,RxRichEd;

type
TMoveMemo = class(TCustomControl)
private
fActive: Boolean;
fTimerTag: Boolean;
fstayTimer: TTimer;
fTimer: TTimer;
fStep : Integer;
fWait : Integer;
fstay : LongInt;
fBgColor: TColor;
Drawing: Boolean;
OffScreen: TBitMap;
fControl :TControl;
fOnComplete: TNotifyEvent;
procedure SetStep(V :Integer);
procedure SetActive(V: Boolean);
procedure SetTimer;
procedure ResetTimer;
procedure SetStay(V: LongInt);
procedure SetWait(V:Integer);
procedure OnTimer(Sender: TObject);
procedure OnStayTimer(Sender: TObject);
procedure SetBgColor(V:TColor);
procedure PaintFrame(ACanvas:TCanvas);
{ Private declarations }
public
Memo:TRxRichEdit;
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
{ Public declarations }
protected
procedure Paint ; override;
{ protected declarations }
published
property Stay : LongInt Read fStay Write Setstay default 3000;
property Step : Integer Read fStep Write SetStep default 50;
property Wait : Integer Read fWait Write SetWait default 5000;
property Active : Boolean Read fActive Write SetActive default False;
property BgColor: TColor Read fBgColor Write SetBgColor ;
property OnComplete : TNotifyEvent Read fOnComplete Write fOnComplete;
property Visible;
Property OnMouseDown;
property OnMouseUp;
property OnMouseMove;
{ published declarations }
end;

procedure Register ;


implementation

constructor TMoveMemo.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fStep:=50;
fStay:=3000;
fWait:=5000;
fBgColor:=clBlack;
fStayTimer:=Nil;
fTimer:=Nil;
fActive:=False;
fTimerTag:=False;
Drawing:=False;
OffScreen:=TBitMap.Create;

Width:=200;
Height:=200;
//////////////////////////////
Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
end;

destructor TMoveMemo.Destroy;
begin
ResetTimer;
Memo.Clear;
Memo.Free;
OffScreen.Assign(Nil);
OffScreen.Free;
inherited Destroy;
end;

procedure TMoveMemo.PaintFrame(ACanvas:TCanvas);
var
dc:HDC;
MemoCanvas:TCanvas;
MemoRect:TRect;
begin
OffScreen.Width:=ClientWidth;
OffScreen.Height:=ClientHeight;
OffScreen.PixelFormat:=pf4Bit;
MemoCanvas:=TCanvas.Create;
dc:=GetDc(Memo.Handle);
try
MemoCanvas.Handle:=dc;
MemoRect:=Rect(0,0,Memo.Width,Memo.Height);
OffScreen.Canvas.CopyRect(MemoRect,MemoCanvas,MemoRect);
finally
ReleaseDc(Memo.Handle,dc);
MemoCanvas.Free;
end;
ACanvas.Lock;
try
ACanvas.Draw(0,0,OffScreen);
finally
ACanvas.Unlock;
end;
end;

procedure TMoveMemo.Paint;
begin
if not Drawing then begin
Drawing := True;
try
PaintFrame(Canvas);
finally
Drawing := False;
end;
end;
end;

procedure TMoveMemo.SetBgColor(V:TColor);
begin
if fBgColor<>V then begin
fBgColor:=V;
Memo.Color:=fBgColor;
Invalidate;
end;
end;

procedure TMoveMemo.SetStay(V:LongInt);
begin
fStay:=V;
Invalidate;
end;

procedure TMoveMemo.SetWait(V:Integer);
begin
fWait:=V;
Invalidate;
end;

procedure TMoveMemo.OnTimer(Sender: TObject);
var
m:Integer;
begin
fTimer.Tag:=fTimer.Tag+1;
SendMessage(Memo.Handle,WM_VSCROLL,MakeLong(SB_THUMBTRACK,fTimer.Tag),0);
m:=Memo.Perform(EM_POSFROMCHAR,0,0 );
if m=fstayTimer.Tag then begin
fTimerTag:=True;
fTimer.Enabled:=False;
fstayTimer.Interval:=fWait;
fstayTimer.Enabled:=True;
end;
fstayTimer.Tag:=m;
Paint;
end;

procedure TMoveMemo.OnStayTimer(Sender:TObject);
begin
fstayTimer.Enabled:=False;
if fTimerTag then begin
Memo.Clear;
if (Assigned(OnComplete)) then fOnComplete(Self);
end else begin
fTimer.Enabled:=True;
fTimer.Tag:=0;
end;
end;


procedure TMoveMemo.SetTimer;
begin
if (csDesigning in ComponentState) then Exit;
fTimer:=TTimer.Create(Self);
fTimer.Interval:=fStep;
fTimer.Enabled:=False;
fTimer.Tag:=0;
fTimer.OnTimer:=OnTimer;
fstayTimer:=TTimer.Create(Self);
fstayTimer.Interval:=fStay;
fstayTimer.OnTimer:=OnStayTimer;
fstayTimer.Enabled:=True;
fstayTimer.Tag:=0;
fTimerTag:=False;
end;

procedure TMoveMemo.ReSetTimer;
begin
if (Assigned(fstayTimer)) then begin
fstayTimer.Enabled:=False;
fStayTimer:=Nil;
end;
if (Assigned(fTimer)) then begin
fTimer.Enabled:=False;
fTimer:=Nil;
end;
Invalidate;
end;

procedure TMoveMemo.SetActive(V: Boolean);
begin
if fActive<>V then fActive :=V;
if fActive then begin
SetTimer;
end else begin
ResetTimer;
end;
Invalidate;
end;

procedure TMoveMemo.SetStep(V:Integer);
begin
fStep:=V;
Invalidate;
end;

procedure Register ;
begin
RegisterComponents('ActiveX', [TMoveMemo]) ;
end ;

end.
 
说明一下,该控件主要是移动平滑上移RxRichEdit中内容,因为移动时有闪烁,所以,我想
使用一个控件,把RxRichEdit中的内容画到canvas上,实现无闪烁。
 
各位高手帮帮忙吧,我还没有吃晚饭呢。
 
将下面这一段,放在一个重载的createwnd方法中
inherited Create(AOwner);
fStep:=50;
fStay:=3000;
fWait:=5000;
fBgColor:=clBlack;
fStayTimer:=Nil;
fTimer:=Nil;
fActive:=False;
fTimerTag:=False;
Drawing:=False;
OffScreen:=TBitMap.Create;

Width:=200;
Height:=200;
//////////////////////////////
Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
 
我回去试试,还有什么好的方法没有?
先谢谢了。
 
其实这一点我也想到了,不过我不会写这个重载函数。
 
你试试把创建TRxRichEdit的部分放到CreateWnd中
procedure CreateWnd;
begin
inherited CreateWnd;
Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
end;
 
谢谢。我正在试!
 
后退
顶部