Алексей Кузнецов дата публикации 13-04-2007 02:10 | КАТЕГОРИЯ | | БИБЛИОТЕКА.VCL.TComboBox.AV при выборе пустого элемента списка | | ПРОДУКТ | | Delphi 7 | | ПЛАТФОРМА | | Windows |
Баг воспроизводится ТОЛЬКО в Delphi 7.0 он подробно описан на
Quality Central (БАГ номер 2442)
Так как не все посещают QC :) имеет смысл этот баг запостить в камни :)
Вот текст прям с QC. Если кратко — предлагают патчить StdCtrls или писать наследника
Description
Delphi 7 introduced a new bug in TCombobox. When an empty line is present in Items and you select that empty line from the dropdown, an access violation in ntdll.dll occurs.
Steps to Reproduce:
- New Application
- Place a TCombobox on Form1
- Fill the Items property with at least one empty line
- Run the application and choose the empty line from the dropdown
- The Access Violation Occurs
Workarounds
The solution is to change a function in StdCtrls.
When asking windows for LBTEXTLEN and zero is returned then the length of Result will be set to zero and a not initialized PChar
will be passed to windows which results in an access violation. The solution is not only to test for CB_ERR but also for len=0.
(because CB_ERR equals -1 the fast test would be Len>0 but that's not descriptive, decide yourself...)
This is the changed function
function TCustomComboBoxStrings.Get(Index: Integer): string;
var
Len: Integer;
begin
Len := SendMessage(ComboBox.Handle, CB_GETLBTEXTLEN, Index, 0);
if (Len <> CB_ERR) and (Len <> 0) then
begin
SetLength(Result, Len);
SendMessage(ComboBox.Handle, CB_GETLBTEXT, Index, Longint(PChar(Result)));
end
else
SetLength(Result, 0);
end;
|
|
(when you look in the Delphi6 source, you can see they used an array of const (4096 chars), so the setlength (Result, 0) problem was
not present in Delphi6)
If you have a descedant or want to make a descedant of TCustomComboBox, then you can also make a descedant of TCustomComboBoxStrings with an override for the function Get (with the fix in it) override the TCustomComboBox.GetItemsClass and return the class of your own descedant of TCustomCombBoxStrings.
Oh: don't forget to copy the function Add and the procedure Insert form the TComboboxStrings, which is defined in the implementation, so you can't descent from that class.
[TComboBox] [Отображение списков, сеток]
Обсуждение материала [ 01-05-2007 20:18 ] 10 сообщений |