Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2000-03

bug in TWinControl

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Weustink
Hans-Joachim Ott wrote 21 lines
Hi, 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.

Additional remarks: - 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

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 :-)

Marc

Reply by email