bug in TWinControl
weus at quicknet.nl
Wed Mar 8 16:21:56 EST 2000
At 20:37 08-03-2000 +0100, Hans-Joachim Ott wrote:
>I found a bug in TWinControl, wincontrol.inc date 00/04/03.
>Symptom: When a text is assigned to a TEdit (with MyEdit.Text :=
>'...')before its handle is allocated (e.g. immediately after its
>creation), this text is not displayed when the control gets visible.
>Reason: TEdit.Text is TWinControl.SetText, where the text is stored in
>fCaption when the handle is not allocated. When later on in
>TWinControl.CreateWnd the component is created, InitializeWnd is called
>which tries to retrieve the text from Caption and put it to the control
>with SetText. But: Caption is a property which is read by
>TControl.GetText, and in case of csEdit and HandleAllocated (which is
>now true) the text is read from the control (with LM_GETTEXT, which
>returns an empty string) instead of fCaption, so the empty string is
>used in SetText.
>Proposed solution: use fCaption instead of Caption in
>TWinControl.InitializeWnd, this should be correct always when the
>control is being created.
HHmm.... typo? Thanks I'll fix it.
>- I find it very strange that TControl.GetText has a decision on the
>ControlStyle. Should this not be implemented by defining GetText as
>virtual and overriding it in descendant classes?
Looking at delphi:
GetText is private. It calls gettextbuf and here the text is retrieved
throug an WM_GETTEXT.
This way it is in fact virtual.
>- GetText should return fCaption if HandleAllocated = false, instead of
>'Edit' (see TControl.GetText).
OK, this is a result of our change a while ago in the way controls are
created. Not all controls have been looked at thoroughly. Thanx
>BTW: I would volunteer to work on a control, especially on Grids, but I
>don't have much spare time, so I fear it would take months to finish one
At least there will be a control :-)
More information about the Lazarus