在Delphi 10.3.2中,当我以编程方式在具有“CharCase = ecLowerCase”(或 ecUpperCase)的 TComboBox 中插入项目时,我收到错误
Project XXXX raise exception class EOutOfResources with message 'Unable to insert a line'
只有当我将单元SHAREMEM添加到我的项目中(我需要引用该单元,因为我必须与 DLL 交换动态字符串)。
似乎该错误与我在过程 TComboBoxStrings.Add() (unit StdCtrls.pas) 中找到的此注释有关:来自 Windows SDK 文档:Comclt32.dll 版本 5.0 或更高版本:如果设置了 CBS_LOWERCASE 或 CBS_UPPERCASE,则 Unicode CB_ADDSTRING 的版本会改变字符串。如果使用只读全局内存,这会导致应用程序失败。
program combo_lowercase;
uses ShareMem,
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Unit1;
interface
uses Forms, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Controls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
combo: TComboBox;
procedure FormCreate(Sender: TObject);
end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
combo.Items.Clear;
combo.Items.Add('AAAAAAAAAAAAAA');
combo.Items.Add('bbbbbbbbbbbbbb');
combo.Items.Add('CCCCCccccccccc');
combo.Items.Add('ddddddDDDDDDDD');
end;
end.
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 206
ClientWidth = 496
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object combo: TComboBox
Left = 48
Top = 20
Width = 145
Height = 21
Style = csDropDownList
CharCase = ecLowerCase
TabOrder = 0
end
end
有解决方法吗?提前致谢。