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
====================================================================