2

インターネットで長い間検索した後、見つけた情報を使用して、このコードを作成して、コントロールのヒントのフォント サイズを変更しました。しかし、割り当てようとするとMessage.HintInfo.HintWindowClass:=HintWin;エラーが発生します: E2010 Incompatible types: 'THintWindowClass' and 'THintWindow'. タイプキャストしようとするTHintWindowClass(HitWin)と、アクセス違反が発生します。私は何をすべきか ?

この同様の質問で、Remy Lebeau は次のように述べています。意味。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMyButton = class(TButton)
  protected
    HintWin: THintWindow;
    procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    MyButton: TMyButton;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 MyButton:=TMyButton.Create(Form1);
 MyButton.Parent:=Form1;
 MyButton.Caption:='Test';
 MyButton.Left:=100;
 MyButton.Top:=100;
 MyButton.ShowHint:=true;
end;

constructor TMyButton.Create(AOwner: TComponent);
begin
 inherited;
 HintWin:=THintWindow.Create(self);
 HintWin.Canvas.Font.Size:=24;
end;

destructor TMyButton.Destroy;
begin
 HintWin.Free;
 inherited;
end;

procedure TMyButton.CMHintShow(var Message: TCMHintShow);
begin
 inherited;
 Message.HintInfo.HintWindowClass:=HintWin;
 Message.HintInfo.HintStr:='My custom hint';
end;

end.
4

1 に答える 1