Board index » cppbuilder » Re: Edit control SelStart and SelLength

Re: Edit control SelStart and SelLength


2003-10-22 04:37:45 AM
cppbuilder8
Remy Lebeau (TeamB) wrote:
Quote
"Edward Diener" < XXXX@XXXXX.COM >wrote in message
news:3f9477da$ XXXX@XXXXX.COM ...

>The question is: does -1 really mean less than 0 instead of
>specifically -1.

If they say "-1" then they mean "-1".
Unfortunately when one receives an EM_SETSEL from the VCL packaging of
TMessage, the -1 is not 0xffffffff but 0x80000000. So the bug appears to be
the VCL's.
 
 

Re:Re: Edit control SelStart and SelLength

Todd Brylski wrote:
Quote
"Edward Diener" < XXXX@XXXXX.COM >wrote in message
news:3f9477da$ XXXX@XXXXX.COM ...

>Not necessarily. Often an unsigned int will be used and -1 really
>means (-1)(unsigned int), or 0xffffffff, which us the highest
>unsigned int number.

Yes, I agree. -1 == -1
Problem solved.
To what are you agreeing ?
 

Re:Re: Edit control SelStart and SelLength

"Edward Diener" < XXXX@XXXXX.COM >wrote in message
Quote
Unfortunately when one receives an EM_SETSEL from the VCL
packaging of TMessage, the -1 is not 0xffffffff but 0x80000000.
So the bug appears to be the VCL's.
The VCL is *not* doing any additional processing or conversions on the
values. It is using/returning whatever the API itself uses/returns. Here
are the actual VCL snippets:
TSelection = record
StartPos, EndPos: Integer;
end;
function TCustomEdit.GetSelStart: Integer;
begin
SendMessage(Handle, EM_GETSEL, Longint(@Result), 0);
end;
procedure TCustomEdit.SetSelStart(Value: Integer);
begin
SendMessage(Handle, EM_SETSEL, Value, Value);
end;
function TCustomEdit.GetSelLength: Integer;
var
Selection: TSelection;
begin
SendMessage(Handle, EM_GETSEL, Longint(@Selection.StartPos),
Longint(@Selection.EndPos));
Result := Selection.EndPos - Selection.StartPos;
end;
procedure TCustomEdit.SetSelLength(Value: Integer);
var
Selection: TSelection;
begin
SendMessage(Handle, EM_GETSEL, Longint(@Selection.StartPos),
Longint(@Selection.EndPos));
Selection.EndPos := Selection.StartPos + Value;
SendMessage(Handle, EM_SETSEL, Selection.StartPos,
Selection.EndPos);
SendMessage(Handle, EM_SCROLLCARET, 0,0);
end;
Gambit
 

{smallsort}

Re:Re: Edit control SelStart and SelLength

"Edward Diener" < XXXX@XXXXX.COM >wrote in message
Quote
To what are you agreeing ?
Read his message again, he said what we was agreeing to:
"-1 == -1"
Gambit
 

Re:Re: Edit control SelStart and SelLength

Remy Lebeau (TeamB) wrote:
Quote
"Edward Diener" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Unfortunately when one receives an EM_SETSEL from the VCL
>packaging of TMessage, the -1 is not 0xffffffff but 0x80000000.
>So the bug appears to be the VCL's.

The VCL is *not* doing any additional processing or conversions on the
values. It is using/returning whatever the API itself uses/returns.
Here are the actual VCL snippets: snipped...
What I was talking about is TMessage, not SelStart or SelLength. An
EM_SETSEL message for selecting the entire text in the control, ends up with
a TMessage.WParam value of 0 ( correct ) and a TMessage.LParam value of
0x80000000 ( incorrect ). According to previous posts in this thread,
everybody agrees that if the MS document says that "If the start is 0 and
the end is -1, all the text in the edit control is selected", it means the
end value has to be truly -1, which is 0xffffffff. Why then does one get
0x80000000 from TMessage in this case ?
 

Re:Re: Edit control SelStart and SelLength

"Edward Diener" < XXXX@XXXXX.COM >wrote in message
Quote
What I was talking about is TMessage, not SelStart or SelLength. An
EM_SETSEL message for selecting the entire text in the control, ends
up with a TMessage.WParam value of 0 ( correct ) and a
TMessage.LParam value of 0x80000000 ( incorrect ).
Again, the VCL is not doing any extra conversions or processings when
dealing with TMessage, either. TMessage is generally used as a wrapper for
the MSG structure. What is contained in one is copied as-is to the other.
Please post an actual example that demonstrates what you are claiming.
Quote
According to previous posts in this thread, everybody agrees that
if the MS document says that "If the start is 0 and the end is -1, all
the text in the edit control is selected", it means the end value has to
be truly -1, which is 0xffffffff. Why then does one get 0x80000000
from TMessage in this case ?
TMessage is not used for this in the first place, SendMessage() is called
directly:
procedure TCustomEdit.SelectAll;
begin
SendMessage(Handle, EM_SETSEL, 0, -1);
end;
So I still do not see what you are referring to. Where EXACTLY are you
looking to see such misuse of TMessage?
Gambit
 

Re:Re: Edit control SelStart and SelLength

Remy Lebeau (TeamB) wrote:
Quote
"Edward Diener" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>What I was talking about is TMessage, not SelStart or SelLength. An
>EM_SETSEL message for selecting the entire text in the control, ends
>up with a TMessage.WParam value of 0 ( correct ) and a
>TMessage.LParam value of 0x80000000 ( incorrect ).

Again, the VCL is not doing any extra conversions or processings when
dealing with TMessage, either. TMessage is generally used as a
wrapper for the MSG structure. What is contained in one is copied
as-is to the other. Please post an actual example that demonstrates
what you are claiming.

>According to previous posts in this thread, everybody agrees that
>if the MS document says that "If the start is 0 and the end is -1,
>all the text in the edit control is selected", it means the end
>value has to be truly -1, which is 0xffffffff. Why then does one get
>0x80000000
>from TMessage in this case ?

TMessage is not used for this in the first place, SendMessage() is
called directly:

procedure TCustomEdit.SelectAll;
begin
SendMessage(Handle, EM_SETSEL, 0, -1);
end;

So I still do not see what you are referring to. Where EXACTLY are
you looking to see such misuse of TMessage?
Create a TComboBox derived component. Override ComboWndProc. Handle the
EM_SETSEL message in ComboWndProc, passing it and all other messages to the
base class ComboWndProc. Create an app, drop your derived class on a form,
build the app. Start debugging it and put a break point at your EM_SETSEL
message handler in your component. Now choose a list item from the list
portion of your combo box and click on the item. Windows sends an EM_SETSEL
message to your ComboWndProc selecting the entire text in the control after
the selection has been made. In your EM_SETSEL handler in ComboWndProc you
will see TMessage.WParam as 0 and TMessage.LParam as 0x80000000. If you do
not, then I will pre-apologize for wasting your time. Thanks !
 

Re:Re: Edit control SelStart and SelLength

"Edward Diener" < XXXX@XXXXX.COM >wrote in message
Quote
Create a TComboBox derived component.
The original topic of this discussion was Edit controls, not ComboBox
controls. A ComboBox has special handling for its *internal* Edit control,
you can't treat it the same as a standalone Edit control.
Quote
Override ComboWndProc.
<snip>
Here is my code which I tested under Win98 using BCB5, and under Win2K using
BCB6:
class TMyComboBox : public TComboBox
{
protected:
void __fastcall ComboWndProc(TMessage &Message, HWND ComboWnd, void
*ComboProc);
public:
__fastcall TMyComboBox(TComponent *Owner);
};
__fastcall TMyComboBox::TMyComboBox(TComponent *Owner)
: TComboBox(Owner)
{
}
void __fastcall TMyComboBox::ComboWndProc(TMessage &Message, HWND
ComboWnd, void *ComboProc)
{
if( Message.Msg == EM_SETSEL )
{
if( Message.LParam == 0x80000000 )
Beep(); // <- breakpoint on this line
}
TComboBox::ComboWndProc(Message, ComboWnd, ComboProc);
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TMyComboBox *cb = new TMyComboBox(this);
cb->Parent = this;
cb->Items->Add("test");
}
When the program is run in the de{*word*81} - the breakpoint is *never* reached.
The LParam is never 0x80000000. Under Win98, the LParam is always
0xFFFFFFFF. Under Win2K, the LParam is always 0x7FFFFFFFF (aka MaxInt,
which is the same end effect as specifying -1, only it is specifying an
explicit character index instead of using -1 to determine it dynamically).
Quote
In your EM_SETSEL handler in ComboWndProc you will see
TMessage.WParam as 0 and TMessage.LParam as 0x80000000.
Nope.
Quote
If you do not, then I will pre-apologize for wasting your time.
Apology accepted.
Gambit
 

Re:Re: Edit control SelStart and SelLength

Remy Lebeau (TeamB) wrote:
Quote
"Edward Diener" < XXXX@XXXXX.COM >wrote in message
news:3f95d4ab$ XXXX@XXXXX.COM ...

>Create a TComboBox derived component.

The original topic of this discussion was Edit controls, not ComboBox
controls. A ComboBox has special handling for its *internal* Edit
control, you can't treat it the same as a standalone Edit control.

>Override ComboWndProc.
<snip>

Here is my code which I tested under Win98 using BCB5, and under
Win2K using BCB6: snipped...

When the program is run in the de{*word*81} - the breakpoint is *never*
reached. The LParam is never 0x80000000. Under Win98, the LParam is
always 0xFFFFFFFF. Under Win2K, the LParam is always 0x7FFFFFFFF
(aka MaxInt, which is the same end effect as specifying -1, only it
is specifying an explicit character index instead of using -1 to
determine it dynamically).
No 0x7fffffff is not the same as specifying -1. Saying that it is specifying
a character index covers over the fact that one can not successfully test
for -1, which is what the documentation says it should be to denote that all
the text in the edit control has been selected . This is incorrect of the
VCL, or the Windows documentation is wrong.
I don't know why I am getting 0x80000000 but I will check it out.
 

Re:Re: Edit control SelStart and SelLength

"Edward Diener" < XXXX@XXXXX.COM >wrote in message
Quote
No 0x7fffffff is not the same as specifying -1.
I did not say that it was *exactly* the same. I said that it was the same
*end effect*. Specifying -1, the edit control will figure out the actual
number of characters it contains so that it can know how many characters to
select. On the other hand, if you specify an index that is greater than the
index of the last character, such as specifying MaxInt, then the edit
control will figure out the number of actual characters it contains so that
it can then adjust the specified index so that it can know how many
characters to select. Either way, the total number of characters actually
contained will be selected. Thus, the same *end effect* is achieved either
way.
Quote
Saying that it is specifying a character index covers over the fact
that one can not successfully test for -1
Huh? Of course it can test for -1. It is just the simple fact that the OS
is not actually using -1 to begin wtih.
Quote
This is incorrect of the VCL
The VCL is simply receiving whatever message was sent to it by the OS. If
the OS itself did not specify -1, there's nothing the VCL can do about that,
the issue is with the OS itself.
Quote
or the Windows documentation is wrong.
It is not complete enough to explain the differences between the OSes, at
least. It would not be the first time Microsoft has done that.
Gambit