⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valcombobox.pas

📁 自己封装的:日期控件(dataX)
💻 PAS
字号:
unit VALComboBox;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Menus, Dialogs, StdCtrls;
type
TValComboBox = class(TComboBox)
private
FValue: PString;
FValues: TStrings;
FOnChange: TNotifyEvent;
function GetValue: string;
function GetButtonValue(Index: Integer): string;
procedure SetValue(const Value: string);
procedure SetValues(Value: TStrings);
protected
procedure Change; dynamic;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Value: string read GetValue write SetValue;
property ItemIndex;
published
property Values: TStrings read FValues write SetValues;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;

procedure Register;
implementation

constructor TValComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FValue := NullStr;
FValues := TStringList.Create;
style := csDropDownList;
end;

destructor TValComboBox.Destroy;
begin
DisposeStr (FValue);
FValues.Free;
inherited Destroy;
end;

procedure TValComboBox.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
end;

function TValComboBox.GetValue : string;
begin
   if ItemIndex<>-1 then
      result:=values[itemindex]
   else
      result:='';   
end;

function TValComboBox.GetButtonValue(Index: Integer): string;
begin
if (Index < FValues.Count) and (FValues[Index] <> '') then
Result := FValues[Index]
else if (Index < Items.Count) then
Result := Items[Index]
else
Result := '';
end;

procedure TValComboBox.SetValue (const Value: string);
var
I : Integer;
begin
AssignStr(FValue, Value);
if (ItemIndex < 0) or (GetButtonValue(ItemIndex) <> Value) then
begin
if (ItemIndex >= 0) then ItemIndex := -1;
for I := 0 to Items.Count - 1 do
begin
if GetButtonValue(I) = Value then
begin
ItemIndex := I;
break;
end;
end;
Change;
end;
end;


procedure TValComboBox.SetValues(Value: TStrings);
begin
FValues.Assign(Value);
end;

procedure TValComboBox.Change;
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure Register;
begin
RegisterComponents('Samples', [TValComboBox]);
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -