Ho iniziato a creare un nuovo componente in Delphi 6 Pro. Attualmente ha solo una singola proprietà pubblicata da TFont. Tuttavia, quando rilascio il componente su un modulo in fase di progettazione e faccio clic sul pulsante di modifica per la proprietà "textAttr_1" (puntini di sospensione), viene visualizzata un'eccezione che dice "impossibile assegnare NIL a un TFont". Cosa sto facendo male che sta causando questo errore? Di seguito è riportato il codice per il componente:Come risolvere il componente Delphi con la proprietà TFont che ottiene "impossibile assegnare NIL a un TFont" in fase di progettazione?
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.
Grazie, David. –
Non dimenticare di aggiungere un gestore di eventi 'OnChange' in modo che il componente possa reagire alle modifiche anche nelle sottoproprietà del font. –
@Remy Lebeau - buona idea e grazie, lo farò. –