Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 339447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:31:26+00:00 2026-05-12T10:31:26+00:00

Is it possible to set TDateTimePicker’s font to italic? I am doing it in

  • 0

Is it possible to set TDateTimePicker’s font to italic? I am doing it in this code

var
  DatEdit : TDateTimePicker;
begin
  //I know Canvas is a stupid name for TPanel
  DatEdit:=TDateTimePicker.Create(Canvas);

  DatEdit.OnEnter := CtrlInputProc;
  DatEdit.OnExit := CtrlExitProc;
  DatEdit.Enabled := false;
  DatEdit.Font.Style := DatEdit.Font.Style + [fsItalic]; //this line creates an exception
  DatEdit.Parent := Canvas;

end;

And every time code executes last line, an EInvalidOperation exception is thrown with a message:

„Control” has no parent window.

Is this Delphi 5 feature, or am I doing something wrong?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:31:26+00:00Added an answer on May 12, 2026 at 10:31 am

    Yes, you are doing something wrong. 🙂

    Some aspects of a window based control require that the control be placed on it’s container window. This usually reflects some requirement in the underlying Window Class itself (not the VCL class, but the MS Windows window object representing the control).

    In this case, simply move your assignment of the Parent property so that it occurs BEFORE you attempt to change the Font.Style :

      DatEdit.OnEnter := CtrlInputProc;
      DatEdit.OnExit := CtrlExitProc;
      DatEdit.Enabled := false;
      DatEdit.Parent := Canvas;
      DatEdit.Font.Style := DatEdit.Font.Style + [fsItalic];
    

    I don’t know if the font can be successfully set to italic in this way or not, but this should at least address your exception.

    UPDATE: I have confirmed that the font can be made italic in this way, as long as you have first set the control Parent. (I used Delphi 2009 ,but I’d be surprised if it didn’t work in Delphi 5)

    FYI: I would strongly recommend a different choice of name for that “Canvas” panel control.

    Addendum: ——-

    It is the call to InvalidateRect() in the CMFontChanged() message handler that requires a Window Handle (which in turn requires that the control be parented).

    If you absolutely need to be able to set the Parent after modifying the Font, you could derive your own control class from TDateTimePicker and implement a response to the CMFontChanged() message that suppresses the inherited behaviour unless the control is parented:

    type
      TMyDateTimePicker = class(TDateTimePicker)
      protected
        procedure CMFontchanged(var Message: TMessage); message CM_FONTCHANGED;
      end;
    
    
      procedure TMyDateTimePicker.CMFontchanged(var Message: TMessage);
    
        procedure AdjustHeight;
        var
          DC: HDC;
          SaveFont: HFont;
          SysMetrics, Metrics: TTextMetric;
        begin
          DC := GetDC(0);
          try
            GetTextMetrics(DC, SysMetrics);
            SaveFont := SelectObject(DC, Font.Handle);
            GetTextMetrics(DC, Metrics);
            SelectObject(DC, SaveFont);
          finally
            ReleaseDC(0, DC);
          end;
          Height := Metrics.tmHeight + (GetSystemMetrics(SM_CYBORDER) * 8);
        end;
    
      begin
        if HasParent then
          inherited
        else
          AdjustHeight;
      end;
    

    Note that the AdjustHeight() procedure is reproduced from a private method of TDateTimePicker. If you are only changing the Font.Style you may not need to reproduce this code and can remove it and the call to it, but if you alter other properties of the Font then this should ensure that the control is correctly sized.

    When you call inherited the private AdjustHeight() mechanism is invoked so there is no need to call the local copy of that procedure in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

would it be possible to set an int value to begin with a zero?
Does anyone know if it is possible set up a Dialog in Microsoft Dynamics
Is possible to set an image as an iPhone application unique icon in code
Is it possible to set code behind a resource dictionary in WPF. For example
Possible Duplicate: Set array key as string not int? I know you can do
Is it possible to set different font sizes in different split views in vim?
In Java SE it is possible set the cause of an exception using initCause
Possible Duplicate: Set Locale programatically I would like to create an english/spanish option choice
Is it possible to set different colors for different rows in (dynamic) ListView? I
Is it possible to set up a cron job that will execute a php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.