3

Summarization:
(1) This is very likely to be a bug. However, I cannot say for sure whether it is more related to 64bit OS, or VCL, or MFC wrapper. Please check the answers and comments below from Delphi experts.
(2) Workaround for me:
a. The situation is that I have six key-value pairs to show in the status bar. The values will be changed in run time.
b. It seems I cannot set text for more than 10 panels.
c. In this respect, I will use six calls of set text for the values, and use two calls for set text for the last two keys. Thus, I don't have to exceed the 10 limit.
d. In order to make set text work, I need provide different text that it already has.
e. Sample code can thus be described as:

// 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'

==================================================================

In my Windows 7 X64, the statusBar does not show text for the panels starting from the 11th correctly.

(1) New an empty VCL application project without saving it, if I set the Text for the 11th status panel at design time, the text will not be shown at all at run time. (See the attached pictures.)

(2) If I save it and reopen it, the text will also not be shown in design time.

(3) If I set the Text at run time, the text will be shown only when the new text is different from the old one. Say the Text for the 11th panel is set to 'try' at design time:

Self.stat1.Panels[10].Text := 'try';         // 'try' is not shown   
self.stat1.Panels[10].Text := 'try_';        // 'try_' is shown

(4) This behavior only happens on my Windows 7 X64, but not on my Windows XP.

(5) I would think the same behavior allpies to all Delphi versions.

(6) It seems the behavior is more related to Windows version than to Delphi. I mean, the same sample application will shown the above behavior on Windows 7 but not on Windows XP.

(7) A sample dfm file is dumped as below:

    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) Sample pictures:
Designtime
rumtime

Could some one help to comment on the possible reason? Any suggestion is appreciated!

SOUser
  • 3,802
  • 5
  • 33
  • 63

3 Answers3

3

It doesn't show beyond the 10th in design-time:

enter image description here

But at run-time is looks like this:

enter image description here

All properties set in the .dfm file.

As to why it is like this I've no idea. But since it behaves fine at run-time I don't think will cause any serious problems.


As requested by Warren, here's my .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
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    Can you dump your DFM as text and append? – Warren P Mar 16 '11 at 12:30
  • @David:Thanks very much for your time! Oh my god, the behavior is reversed in your machine! In my machine, the text is not shown in run time instead. :D – SOUser Mar 16 '11 at 12:33
  • 1
    I think with three of us reproducing it, the sensible answer is, this is a bug in MS Common Controls library. I wonder why it starts screwing up, only after my second try – Warren P Mar 16 '11 at 12:37
  • 1
    @David: Not a problem on your system. However, Xichen sees same behaviour at runtime. Gives me a bad feeling. – Warren P Mar 16 '11 at 12:39
  • 1
    @Warren It never occurred to me that the behaviour might be different on different systems. Weird! – David Heffernan Mar 16 '11 at 12:40
  • 1
    What is even more weird is this: MS Visual Studio 2008 winforms applications do NOT LET YOU ADD more than 10 panels to a status bar. Perhaps they got a memo that we didn't get? Oh wait. They do let you. You just have to change the text to make it smaller. – Warren P Mar 16 '11 at 12:45
  • @David, @Warrent: After I save the project, and reopen it, the text after the 10th panels is gone both in design time and run time. (I have edited my question to reflect this) – SOUser Mar 16 '11 at 12:55
  • 2
    This is trouble in 64 bit OS. It is broken on WinXP x64 and on Win7 x64. Compiled with Delphi 2006 and 2010. – DiGi Mar 16 '11 at 13:05
  • 1
    No, sorry :( Even custom paint is broken. – DiGi Mar 16 '11 at 13:23
  • 1
    Reproduced here, Win 7 64 bit, does not show in designer, but shows ok in runtime. Flipping the BiDiMode value has the effect of (temporarily) correcting the display in the designer, may be worth trying this at runtime? Cannot test here as it works ok at runtime. – HMcG Mar 16 '11 at 14:00
  • 1
    I remember MS Common Controls version changes between Win 95, 98, and 2000 caused me merry hell for many years. Since the XP release, things in MS Common Controls, have been stable, until I see this. – Warren P Mar 16 '11 at 16:40
  • @DiGi: Thanks for your time! @HMcG: Thank you very much for your suggestion! @Warren: Thank you very much for sharing your experience! – SOUser Mar 17 '11 at 11:38
2

I wanted to say "It works for me, on windows 7, 64 bit, with delphi XE." In fact, it did work, the first time I dropped it onto the form, it all worked great. And I thought, you're doing something wrong. Then it hit me, after the second time, I reopened the form.

Now it always fails.

I think you should start with a new blank project like I did, and do just the one thing. That takes all the other things you did out of the code, that are messing you up.

I call this the "file new" test. If you can't reproduce something in a new application, that contains only the code or controls you are unsure about, don't bother asking anybody else to do it for you.

enter image description here

Here is my initial try, it worked:

Second time I reopened the form, it failed at designtime, the same way it failed for David H.

Dump the widths of the panels to a memo like this:

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;

The VCL Status Bar wraps an MS Common control, which either has a bug, or the VCL is wrapping it wrong. Since this doesn't happen on XP, I think you've found a new MS Common Controls bug in Win7.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • @Warren: I do use a new empty project :) – SOUser Mar 16 '11 at 12:34
  • @Warren: `If you can't reproduce something in a new application, that contains only the code or controls you are unsure about, don't bother asking anybody else to do it for you.` I always bear it in mind. – SOUser Mar 16 '11 at 12:34
  • @Warren: You mean in your machine the text is only shown in run time? It is strange but in my machine the text is indeed only shown in design time. :D – SOUser Mar 16 '11 at 12:38
  • 1
    This also reproduces in Win7/64bit, on Delphi 7 VCL. I seriously doubt this is a VCL bug. It has to be a regression in the MS Common controls library. With crap like that floating around in the library, I would rip this out, and use a non-COMMON-controls status bar. – Warren P Mar 16 '11 at 12:41
  • @Warren: Thank you very much for your suggestion! Could you help to recommend one `non-COMMON-controls status bar`? – SOUser Mar 16 '11 at 12:56
  • 1
    I use Toolbar2000+spTBX, others use Developer Express, or TMS. – Warren P Mar 16 '11 at 16:38
  • 1
    For your case (12+ pieces of text) I would just use TPaintBox. :-) – Warren P Mar 16 '11 at 16:47
  • @Warren: Thank you very much for sharing your experience! Also, thanks for your suggestion. – SOUser Mar 17 '11 at 11:37
2

I found a similar problem for ownerdraw panels. DrawPanel event is not called on panels with an index > 6 in Win 7/64bit. I found that windows does not send WM_DRAWITEM message to these panels. Solution that worked in my case is to set the WS_EX_COMPOSITED style to statusbar.

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;
Eugene
  • 94
  • 2
  • 2