Tôi đã bắt đầu xây dựng một thành phần mới trong Delphi 6 Pro. Hiện tại nó chỉ có một tài sản được xuất bản TFont. Tuy nhiên, khi tôi thả thành phần trên Biểu mẫu vào thời gian thiết kế và nhấp vào nút chỉnh sửa cho thuộc tính "textAttr_1" (dấu ba chấm), tôi nhận được Ngoại lệ nói "không thể gán NIL cho TFont". Tôi đang làm sai điều gì gây ra lỗi này? Bên dưới là mã cho thành phần:Làm thế nào để sửa chữa thành phần Delphi với thuộc tính TFont được "không thể gán NIL cho một TFont" tại thời điểm thiết kế?
unit JvExtendedTextAttributes;
interface
uses
Windows, Messages, SysUtils, Classes, JvRichEdit, Graphics;
type
TJvExtendedTextAttributes = class(TComponent)
private
{ Private declarations }
protected
{ Protected declarations }
FTextAttr_1: TFont;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
published
{ Published declarations }
property textAttr_1: TFont read FTextAttr_1 write FTextAttr_1;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('FAVORITES', [TJvExtendedTextAttributes]);
end;
// ---------------------------------------------------------------
constructor TJvExtendedTextAttributes.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTextAttr_1 := TFont.Create;
end;
// ---------------------------------------------------------------
end.
Cảm ơn bạn David. –
Đừng quên thêm một trình xử lý sự kiện 'OnChange' để thành phần của bạn có thể phản ứng với những thay đổi trong các phần con của Font. –
@Remy Lebeau - ý tưởng hay và cảm ơn, sẽ làm. –