Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
- type
- TListBox = class(StdCtrls.TListBox)
- private
- FItemIndex: Integer;
- FOnChange: TNotifyEvent;
- procedure CNCommand(var AMessage: TWMCommand); message CN_COMMAND;
- protected
- procedure Change; virtual;
- procedure SetItemIndex(const Value: Integer); override;
- published
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- end;
- TForm1 = class(TForm)
- ListBox1: TListBox;
- Edit1: TEdit;
- procedure FormCreate(Sender: TObject);
- procedure ListBox1OnChange(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- { TListBox }
- procedure TListBox.Change;
- begin
- if Assigned(FOnChange) then
- FOnChange(Self);
- end;
- procedure TListBox.CNCommand(var AMessage: TWMCommand);
- begin
- inherited;
- if (AMessage.NotifyCode = LBN_SELCHANGE) and (FItemIndex <> ItemIndex) then
- begin
- FItemIndex := ItemIndex;
- Change;
- end;
- end;
- procedure TListBox.SetItemIndex(const Value: Integer);
- begin
- inherited;
- if FItemIndex <> ItemIndex then
- begin
- FItemIndex := ItemIndex;
- Change;
- end;
- end;
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- ListBox1.OnChange := ListBox1OnChange;
- end;
- procedure TForm1.ListBox1OnChange(Sender: TObject);
- begin
- if ListBox1.ItemIndex >= 0 then
- Edit1.Text := ListBox1.Items[ListBox1.ItemIndex]
- else
- Edit1.Clear;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement