Delphi 2009의 TButtonedEdit와 같은 구성 요소를 만들려고합니다. 왼쪽과 오른쪽에 두 개의 단추가있는 사용자 지정 TEdit입니다.내 구성 요소 크래시 (TCustomEdit 자손)
내 버전에서는 왼쪽 및 오른쪽 단추에 2 개의 TSpeedButton 개체를 사용합니다.
다음 간단한 코드를 살펴보십시오.
설치하는 것이 좋으며 부품 pallete에서 볼 수 있습니다.
하지만 알 수없는 이유로 애플리케이션을 저장할 수 없습니다. 구성 요소를 추가하고 속성 변경 또는 이벤트 작성을 시작하자마자 Delphi가 즉시 종료됩니다 (충돌이 발생 했습니까?).
나는 무엇이 잘못 되었는가를 모른다. 그러나 이것은 내가 옳지 않다는 것이 나의 첫 번째 구성 요소이다.
문제점을 확인해주세요.
이 구성 요소를 사용하면 Delphi 7.0에서 .dfm을 저장하는 데 문제가있는 것으로 보입니다.
폼에이 구성 요소를 추가 할 때 저장하면 "Unit1.pas"를 저장하라는 메시지가 나타나면 즉시 종료됩니다.
감사합니다.
unit MyButtonedEdit;
interface
uses
Windows, Buttons, Classes, Controls, Forms, Graphics, Messages, StdCtrls;
type
TMyCustomButtonedEdit = class(TCustomEdit)
private
FLeftButton: TSpeedButton;
FRightButton: TSpeedButton;
procedure LeftButtonClick(Sender: TObject);
procedure RightButtonClick(Sender: TObject);
function GetLeftGlyph: TBitmap;
function GetRightGlyph: TBitmap;
procedure SetLeftGlyph(const g: TBitmap);
procedure SetRightGlyph(const g: TBitmap);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure DoLeftButtonClick; virtual; abstract;
procedure DoRightButtonClick; virtual; abstract;
function GetEnabled: boolean; override;
procedure SetEnabled(e: boolean); override;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
property LeftButton: TSpeedButton read FLeftButton write FLeftButton;
property RightButton: TSpeedButton read FRightButton write FRightButton;
property Enabled: boolean read GetEnabled write SetEnabled;
property LeftGlyph: TBitmap read GetLeftGlyph write SetLeftGlyph;
property RightGlyph: TBitmap read GetRightGlyph write SetRightGlyph;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
end;
TMyButtonedEdit = class(TMyCustomButtonedEdit)
private
FOnLeftButtonClick: TNotifyEvent;
FOnRightButtonClick: TNotifyEvent;
protected
procedure DoLeftButtonClick; override;
procedure DoRightButtonClick; override;
public
published
property LeftButton;
property RightButton;
property AutoSelect;
property BorderStyle;
property Color;
property Ctl3d;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property LeftGlyph;
property RightGlyph;
property HideSelection;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property Text;
property Visible;
property OnLeftButtonClick: TNotifyEvent read FOnLeftButtonClick write FOnLeftButtonClick;
property OnRightButtonClick: TNotifyEvent read FOnRightButtonClick write FOnRightButtonClick;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponents',[TMyButtonedEdit]);
end;
{ TMyCustomButtonedEdit }
constructor TMyCustomButtonedEdit.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csSetCaption];
FLeftButton := TSpeedButton.Create(self);
with FLeftButton do begin
Parent := self;
TabStop := false;
Visible := true;
OnClick := LeftButtonClick;
end;
FRightButton := TSpeedButton.Create(self);
with FRightButton do begin
Parent := self;
TabStop := false;
Visible := true;
OnClick := RightButtonClick;
end;
end;
destructor TMyCustomButtonedEdit.Destroy;
begin
FLeftButton.Free;
FRightButton.Free;
inherited;
end;
procedure TMyCustomButtonedEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or WS_CLIPCHILDREN;
end;
function TMyCustomButtonedEdit.GetEnabled: boolean;
begin
result := inherited Enabled;
end;
function TMyCustomButtonedEdit.GetLeftGlyph: TBitmap;
begin
result := FLeftButton.Glyph;
end;
function TMyCustomButtonedEdit.GetRightGlyph: TBitmap;
begin
result := FRightButton.Glyph;
end;
procedure TMyCustomButtonedEdit.LeftButtonClick(Sender: TObject);
begin
DoLeftButtonClick;
SetFocus;
end;
procedure TMyCustomButtonedEdit.RightButtonClick(Sender: TObject);
begin
DoRightButtonClick;
SetFocus;
end;
procedure TMyCustomButtonedEdit.SetEnabled(e: boolean);
begin
inherited Enabled := e;
FLeftButton.Enabled := e;
FRightButton.Enabled := e;
end;
procedure TMyCustomButtonedEdit.SetLeftGlyph(const g: TBitmap);
begin
FLeftButton.Glyph := g;
end;
procedure TMyCustomButtonedEdit.SetRightGlyph(const g: TBitmap);
begin
FRightButton.Glyph := g;
end;
procedure TMyCustomButtonedEdit.WMSize(var Message: TWMSize);
var
b: integer;
begin
if (BorderStyle = bsSingle) and not Ctl3d then
b := 1
else
b := 0;
FLeftButton.Top := b;
FLeftButton.Height := ClientHeight - b * 2;
FLeftButton.Width := FLeftButton.Height;
FLeftButton.Left := b;
FRightButton.Top := b;
FRightButton.Height := ClientHeight - b * 2;
FRightButton.Width := FRightButton.Height;
FRightButton.Left := ClientWidth - FRightButton.Width - b;
end;
{ TMyButtonedEdit }
procedure TMyButtonedEdit.DoLeftButtonClick;
begin
inherited;
if Assigned(FOnLeftButtonClick) then
FOnLeftButtonClick(Self);
end;
procedure TMyButtonedEdit.DoRightButtonClick;
begin
inherited;
if Assigned(FOnRightButtonClick) then
FOnRightButtonClick(Self);
end;
end.
복합 구성 요소에 없습니다.당신이 설명하는 것은 디자인 타임에 폼에 고정 된 컴포넌트들입니다. 이는 델파이의 IDE 동작입니다. 그러나 VCL의 컴포지트 구성 요소에서도 복합 요소는 하위 구성 요소의 소유자, 즉 복합 요소입니다. –