Einzelnen Beitrag anzeigen

Koloss

Registriert seit: 21. Jul 2010
74 Beiträge
 
Delphi 2 Desktop
 
#14

AW: Property Read Only bei Combobox hinzufügen (Style = csSimple)

  Alt 11. Jan 2019, 11:42
Meine Lösung:

Code:
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.
  Mit Zitat antworten Zitat