我定义的图形组件属性有一个子组件。
发现更新子组件属性时,图形不能重画,一直不能解决。即使在更改子组件属性时加了
invalidate;也不行。
看delphi中,TPen,TBrush这几个子组件,都是定义了句柄的(HPen,HBrush),我们可以自定义句柄么?
可以定义在windows.pas单元内么?
这些组件还有个resource属性,
我需要修改下面这个类的定义么?
TResource = record
Next: PResource;
RefCount: Integer;
Handle: THandle;
HashCode: Word;
case Integer of
0: (Data: TResData);
1: (Font: TFontData);
2: (Pen: TPenData);
3: (Brush: TBrushData);
end;
发现更新子组件属性时,图形不能重画,一直不能解决。即使在更改子组件属性时加了
invalidate;也不行。
看delphi中,TPen,TBrush这几个子组件,都是定义了句柄的(HPen,HBrush),我们可以自定义句柄么?
可以定义在windows.pas单元内么?
这些组件还有个resource属性,
我需要修改下面这个类的定义么?
TResource = record
Next: PResource;
RefCount: Integer;
Handle: THandle;
HashCode: Word;
case Integer of
0: (Data: TResData);
1: (Font: TFontData);
2: (Pen: TPenData);
3: (Brush: TBrushData);
end;
解决方案 »
- delphi webbrowser 页面内转问题(新页面打开)
- 散分,以示感恩!第一帖
- 刚才发现升星星了,特来散分了!!!
- 请有万能查询的模块?
- 如何用Table实现真正的模糊查询
- 在操作excel表时,通过ExcelApp.WorkBooks.open(filename)打开的表,为什么不能保存,提示只读?
- 请教一个关于串口的问题?
- 关于SMS解码的问题: 如何将C++Builder 转为 Delphi 的???
- 如何把我写的东西加入到别的程序里啊
- 一个菜鸟级问题,望指教,谢谢!
- 主程序main调用bpl包中的窗口,bpl窗口显示后如何获取主程序main窗口中的statusbar1.Panels[5].Text内容
- 刚刚写了一个存储过程,请问如何把这个存储过程里的值用显示到Delphi的Edit里。要用到哪些控件和怎么连接
可能是系统得不到重绘的消息。
to Avan_Lau
你可以举个例子么
TYourGraphi = Class(TComponent)
private
SubComp : TXXX;//should be from TComponent
... public
constructor Create(Aowner : TComponent); override;
...
end;
...
constructor Create(AOwner : TComponent);
begin
SubComp := TXXX.Create(AOwner);// or self(should be inherites from tcomponent)
end; 對于無句柄組件,delphi通過isControlMsg-->controlatPos-->perform message,這個過程中,delphi會去遍歷components,若你的子組件不在此列,則無法收到消息,比如重繪消息(paint)
SysUtils, Classes, Controls,Graphics;type TXY=class(TComponent)
//TXY=class(TControl)
private
Fx:integer;
Fy:integer;
procedure set_x(value:integer);
procedure set_y(value:integer);
public
constructor Create(Aowner : TComponent); override;
published
property X:integer read Fx write set_x ;
property Y:integer read Fy write set_y ;
end;
TMLine = class(TGraphicControl)
private
Fpen:Tpen;
Fp1:TXY;
procedure setpen(value:Tpen);
procedure setpoint(value:TXY);
procedure stylechanged(Sender:Tobject);
protected
procedure paint;override;
public
constructor create(aowner:Tcomponent);override;
destructor destroy;override;
published
property Pen:Tpen read fpen write setpen;
property P1:TXY read fp1 write setpoint;
end;procedure Register;implementationconstructor TXY.create(aowner:Tcomponent);
begin
inherited create(aowner);
end;
procedure TXY.set_x(value:integer);
begin
Fx:=value;
//invalidate;end;
procedure TXy.set_y(value:integer);
begin
Fy:=value;
//invalidate;
end;
constructor TMline.create(aowner:Tcomponent);
begin
inherited create(aowner);
height:=80;
width:=80;
fpen:=tpen.Create;
fp1:=TXY.create(self);
fpen.OnChange:=stylechanged;
end;
destructor TMline.destroy;
begin
fpen.Free;
inherited;
end;procedure TMline.setpen(value:Tpen);
begin
fpen.Assign(value);
//invalidate;
end;
procedure TMline.setpoint(value:TXY);
begin //fp1:=value;
if fp1<>value then
begin
if value<>nil then
begin
if assigned(Fp1) and (fp1.Owner=self)then
fp1.Free;
fp1:=value; fp1.FreeNotification(self);
end
else //nil value
begin
if assigned(fp1) and (fp1.Owner<>self) then
begin
fp1:=txy.Create(self);
fp1.SetSubComponent(true);
fp1.FreeNotification(self);
end;
end;
end;
Invalidate;
end;
procedure TMLine.stylechanged(Sender:Tobject);
begin
invalidate;
end;
procedure TMline.paint;
begin
inherited;
with canvas do
begin
pen:=fpen;
MoveTo(fp1.x,fp1.Y);
LineTo(70,70);
end;
end;
procedure Register;
begin
RegisterComponents('User', [TMLine]);
end;end.
//TXY=class(TControl)
用TXY=class(TControl)也是可以的,Tcontrol inherites from TComponent2. 從你的代碼看 公布property P1:TXY read fp1 write setpoint ---fp1應該由外部指定,所以就沒必要在Tmline構建時,再create fp1。3. 關于在setpoint,其實關鍵代碼在你的TMline的paint方法,所以在setpoint里面,應該要能觸發它,不應該調用invalidate,這個只會產生消息 WM_ERASEBKGND and WM_NCPAINT ,所以不會觸發wm_paint,也就不會執行paint方法。
所以你在setpoint直接調用paint
2。如果TMline创建时不创建FP1,在TMline对象属性里不会列出FP1公布的属性。
3.invalidate产生的消息,就是让系统去调用paint方法吧。
我按你的方法修改了一下,还是老样子,真是愁死我了。
根据你的属性类型以及设定属性的方法,我推断:你在外部使用 时,应该会先创建一个TXY类型的对象,然后再进行赋值,这样才能正常使用。不知道你是如何调用的?
我在TXy类的外部,在TMyline类内定义了TXy的对象Fp1。
你说的外部是怎么定义的,这个程序你可以改一下么?