Текущий архив: 2003.02.06;
Скачать: CL | DM;
ВнизСоздание в КОМПОНЕНТЕ нескольких кнопочек... Найти похожие ветки
← →
xn0bys (2003-01-28 16:46) [0]Скажите, пожалуйста, чего здесь надо сделать, чтобы при нажатии на кнопку, например FFirst, он делал сообщение OnClick и передавал бы в обработчик такие данные:
procedure OnSmallDBNavigatorClick(Sender:TObject; Num:Byte);,
где Sender - кнопочка, Num-какой нибудь параметр, например Tag кнопки...
Поможите ПЛИИЗЗ...
type
TNavigateBtn = (nbFirst, nbPrev, nbNext, nbLast,
nbInsert, nbDelete, nbPost, nbCancel);
TButtonSet = set of TNavigateBtn;
ENavClick = procedure (Sender: TObject; Button: TNavigateBtn) of object;
TSmallDBNavigator = class(TCustomPanel)
private
{ Private declarations }
FFirst : TSpeedButton;
FPrev : TSpeedButton;
FNext : TSpeedButton;
FLast : TSpeedButton;
FInsert : TSpeedButton;
FDelete : TSpeedButton;
FPost : TSpeedButton;
FCancel : TSpeedButton;
FText : String;
FLabel : TLabel;
FBWidth : Byte;
FBHeight : Byte;
FOnNavClick : ENavClick;
FVisibleButtons : TButtonSet;
FEnabledButtons : TButtonSet;
FOnClick : TNotifyEvent;
procedure SetText(Value: string);
procedure SetVisibleButtons(Value : TButtonSet);
procedure SetEnabledButtons(Value : TButtonSet);
procedure setBWidth(Value : Byte);
procedure setBHeight(Value : Byte);
Procedure ButClick(Sender:TObject);
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
protected
{ Protected declarations }
property Caption;
procedure AutoPosition;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
//procedure BtnClick(Index: TSpeedButton); virtual;
published
{ Published declarations }
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelInner;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OnClick;
// property OnClick: ENavClick read FOnNavClick write FOnNavClick;
property VisibleButtons: TButtonSet read FVisibleButtons write SetVisibleButtons;
property EnabledButtons: TButtonSet read FEnabledButtons write SetEnabledButtons;
property Text:String read FText write SetText;
property ButtonWidth:Byte read FBWidth write setBWidth;
property ButtonHeight:Byte read FBHeight write setBHeight;
property OnButtClick:TNotifyEvent read FOnClick write FOnClick;
end;
...cut...
← →
xn0bys (2003-01-28 16:47) [1]...cut...
procedure Register;
implementation
procedure Register;
begin
RegisterComponents("Samples", [TSmallDBNavigator]);
end;
constructor TSmallDBNavigator.Create(AOwner: TComponent);
Var i:integer;
procedure CreateBut(name:TSpeedButton;Symbol:Char);
begin
name.Parent:=Self;
name.Left:=Width;
name.Top:=0;
name.Width:=13;
name.Height:=13;
name.Font.Name:="Webdings";
name.Font.Size:=10;
name.Caption:=Symbol;
name.Flat:=True;
//name.Transparent:=True;
name.Tag:=i;
inc(i);
//name.OnClick:=ButClick;
Width:=Width+name.Width;
end;
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csOpaque];
BevelInner:=bvNone;
BevelOuter:=bvNone;
i:=0;
FFirst:=TSpeedButton.Create(self); CreateBut(FFirst,"9");
FPrev:=TSpeedButton.Create(self); CreateBut(FPrev,"3");
FNext:=TSpeedButton.Create(self); CreateBut(FNext,"4");
FLast:=TSpeedButton.Create(self); CreateBut(FLast,":");
FInsert:=TSpeedButton.Create(self); CreateBut(FInsert,"+");
FDelete:=TSpeedButton.Create(self); CreateBut(FDelete,"-");
FPost:=TSpeedButton.Create(self); CreateBut(FPost,"5");
FCancel:=TSpeedButton.Create(self); CreateBut(FCancel,"r");
FBHeight:=13;
FBWidth:=13;
FText:="";
FLabel:=TLabel.Create(self);
FLabel.Parent:=self;
FLabel.Caption:="";
FLabel.Transparent:=True;
FLabel.Left:=0;
FLabel.Top:=0;
FLabel.AutoSize:=True;
Height:=13;
Width:=0;
FEnabledButtons:=[nbFirst, nbPrev, nbNext, nbLast,
nbInsert, nbDelete, nbPost, nbCancel];
FVisibleButtons:=[nbFirst, nbPrev, nbNext, nbLast,
nbInsert, nbDelete, nbPost, nbCancel];
// FPost.Font.Name:="Wingdings";
// FCancel.Font.Name:="Wingdings";
AutoPosition;
end;
destructor TSmallDBNavigator.Destroy;
begin
FFirst.Free;
FPrev.Free;
FNext.Free;
FLast.Free;
FInsert.Free;
FDelete.Free;
FPost.Free;
FCancel.Free;
inherited Destroy;
end;
procedure TSmallDBNavigator.SetVisibleButtons(Value : TButtonSet);
begin
If Value<>FVisibleButtons then
begin
FVisibleButtons:=Value;
AutoPosition;
end;
end;
procedure TSmallDBNavigator.SetEnabledButtons(Value : TButtonSet);
begin
If Value<>FEnabledButtons then
begin
FEnabledButtons:=Value;
AutoPosition;
end;
end;
procedure TSmallDBNavigator.SetText(Value: string);
begin
If Value<>FText then
begin
FText:=Value;
FLabel.Caption:=Value;
end;
end;
procedure TSmallDBNavigator.CMTextChanged(var Message: TMessage);
begin
SetText(Caption);
end;
Procedure TSmallDBNavigator.AutoPosition;
Var i:Integer;
procedure SetAPos(Name:TSpeedButton);
begin
If Name=nil then exit;
Name.Visible:=True;
Name.Left:=i;
Name.Width:=FBWidth;
Name.Height:=FBHeight;
i:=i+FBWidth;
end;
begin
FFirst.Enabled:=(nbFirst in FEnabledButtons);
FPrev.Enabled:=(nbPrev in FEnabledButtons);
Fnext.Enabled:=(nbNext in FEnabledButtons);
FLast.Enabled:=(nbLast in FEnabledButtons);
FInsert.Enabled:=(nbInsert in FEnabledButtons);
FDelete.Enabled:=(nbDelete in FEnabledButtons);
FPost.Enabled:=(nbPost in FEnabledButtons);
FCancel.Enabled:=(nbCancel in FEnabledButtons);
i:=0;
If nbFirst in FVisibleButtons then SetAPos(FFirst) else FFirst.Visible:=False;
If nbPrev in FVisibleButtons then SetAPos(FPrev) else FPrev.Visible:=False;
If nbNext in FVisibleButtons then SetAPos(FNext) else FNext.Visible:=False;
If nbLast in FVisibleButtons then SetAPos(FLast) else FLast.Visible:=False;
If nbInsert in FVisibleButtons then SetAPos(FInsert) else FInsert.Visible:=False;
If nbDelete in FVisibleButtons then SetAPos(FDelete) else FDelete.Visible:=False;
If nbPost in FVisibleButtons then SetAPos(FPost) else FPost.Visible:=False;
If nbCancel in FVisibleButtons then SetAPos(FCancel) else FCancel.Visible:=False;
Width:=i;
end;
procedure TSmallDBNavigator.setBWidth(Value : Byte);
begin
If Value<>FBWidth then
begin
FBWidth:=Value;
AutoPosition;
end;
end;
procedure TSmallDBNavigator.setBHeight(Value : Byte);
begin
If Value<>FBWidth then
begin
Height:=Value;
FBHeight:=Value;
AutoPosition;
end;
end;
procedure TSmallDBNavigator.ButClick(Sender:TObject);
begin
if Assigned(FOnClick) then
FOnClick(Sender);
end;
end.
Чёй-то у меня не получается...
← →
Skier (2003-01-28 16:55) [2]>xn0bys
Создай класс-потомок (кстати в дельфийском навигаторе сделанно именно так...)
TNavButton = class(TSpeedButton)
private
protected
FOnNavClick : ENavClick;
public
procedure Click; override;
end; //TNavButton
procedure TNavButton.Click;
begin
if Assigned(FOnNavClick) then FOnNavClick(Self, Tag);
end;
← →
han_malign (2003-01-28 17:00) [3]> например Tag кнопки...
- поле Tag для того и сделано, что-бы передавать дополнительную информацию в событие, не мудрствуя лукаво...
← →
xn0bys (2003-01-28 17:01) [4]Skier
Сенькс, попробуем завтре...
Страницы: 1 вся ветка
Текущий архив: 2003.02.06;
Скачать: CL | DM;
Память: 0.47 MB
Время: 0.01 c