Einzelnen Beitrag anzeigen

blackdrake

Registriert seit: 21. Aug 2003
Ort: Bammental
618 Beiträge
 
Delphi 10.3 Rio
 
#3

Re: VCL: Property ausblenden bei Ableitung?

  Alt 14. Dez 2007, 22:51
Hallo.

Vielen Dank für die Vorlage. Ich hatte diese CN_NOTIFY-Variante zwar schon gehabt, jedoch bin ich nicht auf die Idee mit stStart.wMonth gekommen.

Folgendes funktioniert nun:

Delphi-Quellcode:
unit ExtMonthCalendar;

interface

uses
  Controls, ComCtrls, Messages, CommCtrl;

type
  TOnGetMonthInfoExtEvent = procedure(Sender: TObject; Month, Year: LongWord;
    var MonthBoldInfo: LongWord) of object;

  TExtMonthCalendar = class(TMonthCalendar)
  private
    FOnGetMonthInfo: TOnGetMonthInfoExtEvent;
    procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
  published
    property OnGetMonthInfo: TOnGetMonthInfoExtEvent read FOnGetMonthInfo
                                                    write FOnGetMonthInfo;
  end;

implementation

procedure TExtMonthCalendar.CNNotify(var Message: TWMNotify);
var
  I, MonthNo: Integer;
  CurState: PMonthDayState;
  YearAdd: integer;
begin
  inherited;

  with Message, NMHdr^ do
  begin
    if code = MCN_GETDAYSTATE then
    begin
      with PNmDayState(NMHdr)^ do
      begin
        FillChar(prgDayState^, cDayState * SizeOf(TMonthDayState), 0);
        if Assigned(FOnGetMonthInfo) then
        begin
          CurState := prgDayState;
          for I := 0 to cDayState - 1 do
          begin
            MonthNo := stStart.wMonth + I;
            if MonthNo > 12 then
            begin
              MonthNo := MonthNo - 12;
              YearAdd := 1;
            end
            else
            begin
              YearAdd := 0;
            end;
            FOnGetMonthInfo(Self, MonthNo, stStart.wYear+YearAdd, CurState^);
            Inc(CurState);
          end;
        end;
      end;
    end;
  end;
end;

end.
(Korrigiert: YearAdd hinzugefügt, Ereignis "OnGetMonthInfo" von TMonthCalendar nun überschrieben und dadurch ersetzt)

Ein Problem hab ich jetzt aber mit der Komponente: Im falle von folgender Verwendung:

Delphi-Quellcode:
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    my_cal: TExtMonthCalendar;
    procedure GetMonthInfo(Sender: TObject; Month, Year: Cardinal; var MonthBoldInfo: Cardinal);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.GetMonthInfo(Sender: TObject; Month, Year: Cardinal;
  var MonthBoldInfo: Cardinal);
var
  x: array of LongWord;
begin
  { zum Test }
  SetLength(x, 2);
  x[0] := month;
  x[1] := year-2000+10;

  (Sender as TMonthCalendar).BoldDays(x, MonthBoldInfo);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  my_cal := TExtMonthCalendar.Create(form1);
  my_cal.Parent := form1;
  my_cal.Left := 100;
  my_cal.top := 100;
  my_cal.Height := 500;
  my_cal.OnGetMonthInfo := GetMonthInfo;
end;
ist die fette hervorhebung der Datumsangaben erst nach einem Monats-Scrollen vorhanden. Ich habe mir die Unit ComCtrls.pas genau angeschaut und nach "OnGetMonthInfo" gesucht. Dort wird OnGetMonthInfo ebenfalls bei der CN_NOTIFY-Message aufgerufen, aber sonst nirgens. Mache ich die Markierung bei einer normalen TMonthCalendar-VCL, dann ist die Markierung von Anfang an da, so als würde OnGetMonthInfo im OnCreate-Ereignis aufgerufen werden.

Gruß
blackdrake
Daniel Marschall
  Mit Zitat antworten Zitat