Board index » delphi » Delphi bug or am I just being stupid?

Delphi bug or am I just being stupid?

Why does the following code not work in Delphi 2 under windows 95?

combobox1.text := 'Why do I not work?';
combobox1.setfocus;
combobox1.selstart := 2;
combobox1.sellength := 2;

Instead of starting the selection from the 2nd character it always
starts at 0.

Is this a bug or am I doing somthing stupid?

Thanks for you help
Justin  

 

Re:Delphi bug or am I just being stupid?


Quote
Justin Ramel wrote:

> Why does the following code not work in Delphi 2 under windows 95?

> combobox1.text := 'Why do I not work?';
> combobox1.setfocus;
> combobox1.selstart := 2;
> combobox1.sellength := 2;

> Instead of starting the selection from the 2nd character it always
> starts at 0.

> Is this a bug or am I doing somthing stupid?

Interesting!  I also noticed that sending it the Windows message
CB_SETEDITSEL doesn't act as advertised either.  Here's my test:

   with ComboBox1 do
      begin
      Text := 'Why do I not work?';
      SetFocus;
      Perform(CB_SETEDITSEL, 2, 4);
      end;

Sorry this probably doesn't help much, but it might lend some credance
to your theory that it's a Delphi bug.  Maybe you could send a
WM_KEYDOWN message to ComboBox1 with VK_RIGHT and VK_SHIFT state
information to select the text you want <== a kludgy hack, but it
might work.

Later,
-Jim Rofkar.

Re:Delphi bug or am I just being stupid?


Quote
Justin Ramel <Justin.Ra...@ncl.ac.uk> wrote:
>Why does the following code not work in Delphi 2 under windows 95?

>combobox1.text := 'Why do I not work?';
>combobox1.setfocus;
>combobox1.selstart := 2;
>combobox1.sellength := 2;

>Instead of starting the selection from the 2nd character it always
>starts at 0.

>Is this a bug or am I doing somthing stupid?

This is a bug in Delphi 2 (the feature is correctly implemented in
Delphi 1) and affects both SelStart and SelLength. I had to fix the
problem in my SLIC component package. Here are the methods for Delphi
2 that you can use to work around this problem...

type
   TSelection = record
      StartPos,EndPos:SmallInt;
   end;

procedure TEicComboBox.SetSelStart(Value:Integer);
var Selection:TSelection;
begin
   Selection.StartPos := Value;
   Selection.EndPos := Value;
   SendMessage(Handle,CB_SETEDITSEL,0,LongInt(Selection));
end;

procedure TEicComboBox.SetSelLength(Value:Integer);
var Selection:TSelection; StartPos,EndPos:LongInt;
begin

SendMessage(Handle,CB_GETEDITSEL,LongInt(@StartPos),LongInt(@EndPos));
   Selection.StartPos := StartPos;
   Selection.EndPos := Selection.StartPos + Value;
   SendMessage(Handle,CB_SETEDITSEL,0,LongInt(Selection));
end;

Hope this helps!

Eric G.V. Fookes ===============<foo...@sc2a.unige.ch>==============
Creator of Delphi (1 & 2) Labeled Input Controls. Download from...
   http://www.unige.ch/sciences/terre/geologie/fookes/delphi.htm
====================================================================

Other Threads