In Delphi 10.3.2, when I programmatically insert items in a TComboBox having "CharCase = ecLowerCase" (or ecUpperCase), I get the error
Project XXXX raise exception class EOutOfResources with message 'Unable to insert a line'
The error only appears when I add to my project the unit SHAREMEM (I need to reference that unit as I have to exchange dynamic strings with a DLL).
It seems that the error is related to this remark I found in the procedure TComboBoxStrings.Add() (unit StdCtrls.pas): From the Windows SDK documentation: Comclt32.dll version 5.0 or later: If CBS_LOWERCASE or CBS_UPPERCASE is set, the Unicode version of CB_ADDSTRING alters the string. If using read-only global memory, this causes the application to fail.
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
Is there a workaround? Thanks in advance.
The code you show does not lead to the error that you report. The only explanation I can come up with to account for the significance of Sharemem
is that its use leads to an erroneous version of borlandmm.dll being loaded. Make sure that your process loads the correct version of that DLL. Copy it from the bin directory to the same directory as your executable.