在Windows 7 x64中,状态栏未正确从第11个开始显示面板的文本
-
25-10-2019 - |
题
摘要:
(1)这很可能是一个错误。但是,我不能确定它是否与64位OS,VCL或MFC包装器有关。请检查下面Delphi专家的答案和评论。
(2)对我的解决方法:
一个。情况是我有 six
核心价值 pairs
在状态栏中显示。值将在运行时间更改。
b。看来我不能 set text
超过 10
面板。
C。在这方面,我会使用 six
电话 set text
对于值,并使用 two
要求 set text
对于最后两个键。因此,我不必超过 10
限制。
d。为了要做 set text
工作,我需要提供已经拥有的不同文本。
e。因此,示例代码可以描述为:
// Designtime
stat1.Panels[0].Text := 'Key1'
stat1.Panels[2].Text := 'Key2'
stat1.Panels[4].Text := 'Key3'
stat1.Panels[6].Text := 'Key4'
stat1.Panels[8].Text := 'Key5__'
stat1.Panels[10].Text := 'Key6__'
// runtime
stat1.Panels[1].Text := 'Value1'
stat1.Panels[3].Text := 'Value2'
stat1.Panels[5].Text := 'Value3'
stat1.Panels[6].Text := 'Value4'
stat1.Panels[9].Text := 'Value5'
stat1.Panels[11].Text := 'Value6'
stat1.Panels[8].Text := 'Key5'
stat1.Panels[10].Text := 'Key6'
==================================================================
在我的Windows 7 X64中,状态栏未正确从第11个开始显示面板的文本。
(1)新的一个空VCL应用程序项目 without
保存它,如果我在设计时间设置第11个状态面板的文本,则在运行时根本不会显示该文本。 (请参阅所附图片。)
(2)如果我保存并重新打开它,则文本也不会在设计时间中显示。
(3)如果我在运行时设置文本,则仅在新文本与旧文本不同时才显示文本。说第11个面板的文本设置为 'try'
在设计时间:
Self.stat1.Panels[10].Text := 'try'; // 'try' is not shown
self.stat1.Panels[10].Text := 'try_'; // 'try_' is shown
(4)此行为仅发生在我的Windows 7 X64上,而不会在Windows XP上发生。
(5)我认为所有Delphi版本的行为都相同。
(6)看来,行为与Windows版本更相关,而不是与Delphi相关。我的意思是,相同的示例应用程序将在Windows 7上显示上述行为,但在Windows XP上没有显示。
(7)示例DFM文件如下:
object Form3: TForm3
Left = 0
Top = 0
Caption = 'Form3'
ClientHeight = 202
ClientWidth = 731
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object stat1: TStatusBar
Left = 0
Top = 183
Width = 731
Height = 19
Panels = <
item
Text = '0'
Width = 50
end
item
Text = '1'
Width = 50
end
item
Text = '2'
Width = 50
end
item
Text = '3'
Width = 50
end
item
Text = '4'
Width = 50
end
item
Text = '5'
Width = 50
end
item
Text = '6'
Width = 50
end
item
Text = '7'
Width = 50
end
item
Text = '8'
Width = 50
end
item
Text = '9'
Width = 50
end
item
Text = '10'
Width = 50
end
item
Text = '11'
Width = 50
end>
ExplicitLeft = 248
ExplicitTop = 152
ExplicitWidth = 0
end
object btn1: TButton
Left = 152
Top = 40
Width = 433
Height = 89
Caption = 'btn1'
TabOrder = 1
OnClick = btn1Click
end
end
(8)示例图片:
有人可以帮助评论可能的原因吗?任何建议都将不胜感激!
解决方案
我想说:“它对我有用,在Windows 7,64位,带Delphi Xe。”实际上,它确实有效,第一次将其放到表单上时,一切都很好。我想,你做错了什么。然后第二次打了我,我重新打开了表格。
现在它总是失败。
我认为您应该像我一样从一个新的空白项目开始,然后做一件事。这使您从代码中所做的所有其他事情都弄乱了您。
我将其称为“新文件”测试。如果您不能在新应用程序中重现某些内容,则仅包含您不确定的代码或控件,请不要打扰其他人为您做。
这是我的最初尝试,它有效:
我第二次重新打开了该表格,它在Design Time失败了,就像David H的失败方式一样。
将面板的宽度倾倒到这样的备忘录:
procedure TForm3.DumpWidths;
var
t:Integer;
begin
for t := 0 to StatusBar1.Panels.Count-1 do begin
Memo1.Lines.Add( '#'+IntToStr(t)+
' width '+
IntToStr(StatusBar1.Panels.Items[t].Width));
end;
end;
VCL状态栏包裹一个具有错误的MS公共控件,或者VCL将其包裹错误。由于在XP上没有发生这种情况,因此我认为您在Win7中找到了一个新的MS Comman Controls Bug。
其他提示
它在设计时间的第十次超出了第十次。
但是在运行时看起来像这样:
.DFM文件中设置的所有属性。
至于为什么这样,我不知道。但是,由于在运行时的行为不错,所以我认为不会引起任何严重的问题。
按照沃伦的要求,这是我的.dfm:
object Form3: TForm3
Left = 0
Top = 0
Caption = 'Form3'
ClientHeight = 105
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object StatusBar1: TStatusBar
Left = 0
Top = 86
Width = 635
Height = 19
Panels = <
item
Text = '1'
Width = 50
end
item
Text = '2'
Width = 50
end
item
Text = '3'
Width = 50
end
item
Text = '4'
Width = 50
end
item
Text = '5'
Width = 50
end
item
Text = '6'
Width = 50
end
item
Text = '7'
Width = 50
end
item
Text = '8'
Width = 50
end
item
Text = '9'
Width = 50
end
item
Text = '10'
Width = 50
end
item
Text = '11'
Width = 50
end
item
Text = '12'
Width = 50
end
item
Text = '13'
Width = 50
end>
end
end
我发现了所有者Draw面板的类似问题。在WIN 7/64位中,drawpanel事件未在索引> 6的面板上进行调用。我发现Windows不会向这些面板发送WM_DRAWITEM消息。在我的情况下使用的解决方案是将WS_EX_COMPOSITED样式设置为状态栏。
procedure TForm1.FormCreate(Sender: TObject);
var
SBHandle: THandle;
begin
...
if CheckWin32Version(5, 1) then
begin
SBHandle:= StatusBar.Handle;
SetWindowLong(SBHandle, GWL_EXSTYLE, GetWindowLong(SBHandle, GWL_EXSTYLE) or WS_EX_COMPOSITED);
end;
...
end;