rwilson032697
asked on
Bizarre problem with Trackbar & Combo box
I have a trackbar and a combobox on a form. In the onchange event of the trackbar I clear the combobox and add some items to it. However, this causes the marker on the trackbar to zoom up to the mouse when it is clicked on the trackbar. If I remove the clear it is ok (but I get a build up of items in the combobox). If I don't do the clear, but delete the individual items I get the same behaviour. As both the trackbar and the combobox are windows common controls I cant track them past the points where the messages are sent to the appropriate handles.
Can anyone help me here?
I am using Delphi 3.02 on NT 4 SP3.
The source for the .DPR, .DFM and .PAS files are below.
program Project3;
uses
Forms,
Unit3 in 'Unit3.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TFo rm1, Form1);
Application.Run;
end.
-------------------------- ---------- ---------- ---------- ------
object Form1: TForm1
Left = 244
Top = 115
Width = 783
Height = 540
Caption = 'Form1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object TrackBar1: TTrackBar
Left = 80
Top = 24
Width = 617
Height = 41
Orientation = trHorizontal
PageSize = 1
Frequency = 1
Position = 0
SelEnd = 0
SelStart = 0
TabOrder = 0
TickMarks = tmBottomRight
TickStyle = tsAuto
OnChange = TrackBar1Change
end
object ComboBox1: TComboBox
Left = 312
Top = 80
Width = 369
Height = 21
ItemHeight = 13
TabOrder = 1
Text = 'ComboBox1'
end
end
-------------------------- ---------- ---------- ---------- -
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, ComCtrls, Menus;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
ComboBox1: TComboBox;
procedure TrackBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.TrackBar1Change(Sen der: TObject);
begin
with combobox1 do
begin
clear;
Items.Add('Start super'); {0}
Items.Add('Start spiral'); {1}
Items.Add('Start equal'); {2}
Items.Add('Start arc'); {3}
Items.Add('Start max'); {4}
Items.Add('End max'); {5}
Items.Add('End arc'); {6}
Items.Add('End equal'); {7}
Items.Add('End spiral'); {8}
Items.Add('End super'); {9}
Items.Add('User super'); {10}
end;
end;
end.
Can anyone help me here?
I am using Delphi 3.02 on NT 4 SP3.
The source for the .DPR, .DFM and .PAS files are below.
program Project3;
uses
Forms,
Unit3 in 'Unit3.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TFo
Application.Run;
end.
--------------------------
object Form1: TForm1
Left = 244
Top = 115
Width = 783
Height = 540
Caption = 'Form1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object TrackBar1: TTrackBar
Left = 80
Top = 24
Width = 617
Height = 41
Orientation = trHorizontal
PageSize = 1
Frequency = 1
Position = 0
SelEnd = 0
SelStart = 0
TabOrder = 0
TickMarks = tmBottomRight
TickStyle = tsAuto
OnChange = TrackBar1Change
end
object ComboBox1: TComboBox
Left = 312
Top = 80
Width = 369
Height = 21
ItemHeight = 13
TabOrder = 1
Text = 'ComboBox1'
end
end
--------------------------
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, ComCtrls, Menus;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
ComboBox1: TComboBox;
procedure TrackBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.TrackBar1Change(Sen
begin
with combobox1 do
begin
clear;
Items.Add('Start super'); {0}
Items.Add('Start spiral'); {1}
Items.Add('Start equal'); {2}
Items.Add('Start arc'); {3}
Items.Add('Start max'); {4}
Items.Add('End max'); {5}
Items.Add('End arc'); {6}
Items.Add('End equal'); {7}
Items.Add('End spiral'); {8}
Items.Add('End super'); {9}
Items.Add('User super'); {10}
end;
end;
end.
I do not understand what the problem is. Your code does work here as i should expect.
What do you mean by ' zoom up to the mouse' ?
What do you mean by ' zoom up to the mouse' ?
(To mvz:
There is a problem: Normally when you click on a TrackBar, the positions changes ONE step towards the mouse cursor, but with rwilson's code the TrackBar's position changes MANY steps, all the way to the mouse cursor!)
I once had the same problem, and it does indeed seem to be a bug in Windows common controls. I got around it by using a TTimer (!!) with an interval of about 1/10th of a second.
The problem appears to be caused when the combobox's items are cleared in the TComboBoxStrings.Clear method if there are 2 or more items in the combo box's list. The CB_RESETCONTENT message sent to the combo box to clear its items "appears" to be the problem???
JB
There is a problem: Normally when you click on a TrackBar, the positions changes ONE step towards the mouse cursor, but with rwilson's code the TrackBar's position changes MANY steps, all the way to the mouse cursor!)
I once had the same problem, and it does indeed seem to be a bug in Windows common controls. I got around it by using a TTimer (!!) with an interval of about 1/10th of a second.
The problem appears to be caused when the combobox's items are cleared in the TComboBoxStrings.Clear method if there are 2 or more items in the combo box's list. The CB_RESETCONTENT message sent to the combo box to clear its items "appears" to be the problem???
JB
Mmm… Before I go accusing Microsoft of buggy common controls, maybe I should get my facts straight. I just wrote the same app in VB 5 and it works fine...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You cracked it mvz.
As far as I can see it fixes the problem perfectly. The fact you call it a word-around is not a problem.
Thanks!
PS: I am curious how you discovered this fix?
As far as I can see it fixes the problem perfectly. The fact you call it a word-around is not a problem.
Thanks!
PS: I am curious how you discovered this fix?
ASKER