关于ToolBar继承问题
{父类}
unit Unit5;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActnMan, ActnCtrls, ComCtrls, ToolWin;type
TForm5 = class(TForm)
tlb1: TToolBar;
tb1: TToolButton;
tb2: TToolButton;
tb3: TToolButton;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form5: TForm5;implementation{$R *.dfm}end.{Unit5 对应的窗体文件}object Form5: TForm5
Left = 0
Top = 0
Caption = 'Form5'
ClientHeight = 223
ClientWidth = 311
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object tlb1: TToolBar
Left = 0
Top = 0
Width = 311
Height = 29
ButtonHeight = 21
Caption = 'tlb1'
ShowCaptions = True
TabOrder = 0
object tb1: TToolButton
Left = 0
Top = 0
Caption = 'tb1'
ImageIndex = 0
end
object tb2: TToolButton
Left = 23
Top = 0
Caption = 'tb2'
ImageIndex = 1
end
object tb3: TToolButton
Left = 46
Top = 0
Caption = 'tb3'
ImageIndex = 2
end
end
end{子类}
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
//
Unit5, ComCtrls, ToolWin;type
TForm1 = class(TForm5)
tb4: TToolButton;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}end.{Unit1 对应的窗体文件}
inherited Form1: TForm1
Caption = 'Form1'
ClientHeight = 232
ClientWidth = 338
ExplicitWidth = 346
ExplicitHeight = 266
PixelsPerInch = 96
TextHeight = 13
inherited tlb1: TToolBar
Width = 338
ExplicitWidth = 338
object tb4: TToolButton [0]
Left = 0
Top = 0
Caption = 'tb4'
ImageIndex = 3
end
inherited tb1: TToolButton
Left = 23
ExplicitLeft = 23
end
inherited tb2: TToolButton
Left = 46
ExplicitLeft = 46
end
inherited tb3: TToolButton
Left = 69
ExplicitLeft = 69
end
end
end
问题,我在子类中添加了一个ToolButton,调整其位置,但是运行效果但是一直在最后面,这是什么情况呀?为什么?如何解决?
{父类}
unit Unit5;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActnMan, ActnCtrls, ComCtrls, ToolWin;type
TForm5 = class(TForm)
tlb1: TToolBar;
tb1: TToolButton;
tb2: TToolButton;
tb3: TToolButton;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form5: TForm5;implementation{$R *.dfm}end.{Unit5 对应的窗体文件}object Form5: TForm5
Left = 0
Top = 0
Caption = 'Form5'
ClientHeight = 223
ClientWidth = 311
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object tlb1: TToolBar
Left = 0
Top = 0
Width = 311
Height = 29
ButtonHeight = 21
Caption = 'tlb1'
ShowCaptions = True
TabOrder = 0
object tb1: TToolButton
Left = 0
Top = 0
Caption = 'tb1'
ImageIndex = 0
end
object tb2: TToolButton
Left = 23
Top = 0
Caption = 'tb2'
ImageIndex = 1
end
object tb3: TToolButton
Left = 46
Top = 0
Caption = 'tb3'
ImageIndex = 2
end
end
end{子类}
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
//
Unit5, ComCtrls, ToolWin;type
TForm1 = class(TForm5)
tb4: TToolButton;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}end.{Unit1 对应的窗体文件}
inherited Form1: TForm1
Caption = 'Form1'
ClientHeight = 232
ClientWidth = 338
ExplicitWidth = 346
ExplicitHeight = 266
PixelsPerInch = 96
TextHeight = 13
inherited tlb1: TToolBar
Width = 338
ExplicitWidth = 338
object tb4: TToolButton [0]
Left = 0
Top = 0
Caption = 'tb4'
ImageIndex = 3
end
inherited tb1: TToolButton
Left = 23
ExplicitLeft = 23
end
inherited tb2: TToolButton
Left = 46
ExplicitLeft = 46
end
inherited tb3: TToolButton
Left = 69
ExplicitLeft = 69
end
end
end
问题,我在子类中添加了一个ToolButton,调整其位置,但是运行效果但是一直在最后面,这是什么情况呀?为什么?如何解决?
2)按2楼所示,将其tb4的parent设置成tlb1,tb4的位置还是跑到最后面了。仍然解决不了?是不是因为继承的,优先Create父类,再创建子类,我尝试了以下方法,将子类新增的tb4.Left:=tb4.Width,结果Run时,可以跑到第一个位置去,这是怎么回事?而用tb4.Left:=0却仍在原位置不变,这又是什么情况?