unit ComboBoxReadOnly;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TComboBox = class(StdCtrls.TComboBox)
private
FReadOnly: Boolean;
LastItemIndex : Integer;
procedure SetReadOnly(const Value: Boolean);
procedure KeyPress(var Key: Char); override;
Procedure CreateWnd; Override;
public
{ Public-Deklarationen }
published
procedure DropDown; override;
procedure CloseUp; override;
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
end;
implementation
procedure TComboBox.CloseUp;
begin
inherited;
ItemIndex := LastItemIndex;
end;
procedure TComboBox.CreateWnd;
begin
inherited;
ReadOnly := FReadOnly;
end;
procedure TComboBox.DropDown;
begin
inherited;
if readonly then
LastItemIndex := ItemIndex;
end;
procedure TComboBox.KeyPress(var Key: Char);
begin
if not readonly then
inherited;
end;
procedure TComboBox.SetReadOnly(const Value: Boolean);
begin
FReadOnly := Value;
if HandleAllocated then
SendMessage(EditHandle, EM_SETREADONLY, Ord(Value), 0);
end;
end.