Recent

Author Topic: [SOLVED] How to set FirstDayofWeek in TCalendarDialog?  (Read 1054 times)

HexLaden

  • New Member
  • *
  • Posts: 14
[SOLVED] How to set FirstDayofWeek in TCalendarDialog?
« on: September 09, 2023, 09:17:31 pm »
I'd like to set first day of week on a calendar dialog to monday.
TCalendarDialog has a TCalendar field (FCalendar) that is private, so
Code: Pascal  [Select][+][-]
  1. CalendarDialog.FCalendar.FirstDayofWeek := dowMonday;
is not an option. What workaround do you suggest?

Thank you.
(Lazarus 2.2.0 on Win10)
« Last Edit: September 10, 2023, 08:50:30 am by HexLaden »

TRon

  • Hero Member
  • *****
  • Posts: 3769
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #1 on: September 09, 2023, 09:21:10 pm »
According to the wiki using DisplaySettings allows you to adjust the default settings.

I also noted this post from wp:
Quote
I committed a new version of TCalendar to Laz-trunk (r63220) in which the option dsStartMonday has been removed and replaced by a new Delphi-compatible(*) property FirstDayOfWeek which can be set to any weekday. The default value, dowDefault, is the default provided by the widgetset. Note that still only the win32, qt and qt5 widgetsets provide an interface to change the first day of the week, in the other cases the property is without effect leaving the widgetset default unchanged.
« Last Edit: September 09, 2023, 09:27:47 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

dsiders

  • Hero Member
  • *****
  • Posts: 1324
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #2 on: September 09, 2023, 10:33:34 pm »
According to the wiki using DisplaySettings allows you to adjust the default settings.

I also noted this post from wp:
Quote
I committed a new version of TCalendar to Laz-trunk (r63220) in which the option dsStartMonday has been removed and replaced by a new Delphi-compatible(*) property FirstDayOfWeek which can be set to any weekday. The default value, dowDefault, is the default provided by the widgetset. Note that still only the win32, qt and qt5 widgetsets provide an interface to change the first day of the week, in the other cases the property is without effect leaving the widgetset default unchanged.

The wiki page is outdated as TDisplaySetting no longer includes the start day-of-week enumeration values.

While TCalendar has the property you need, the calendar is protected on the dialog. And the dialog provides no property corresponding to the calendar setting. So you'd have to hack access the calendar member to set its value.

Sounds like a feature request/bug report to me.


Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

HexLaden

  • New Member
  • *
  • Posts: 14
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #3 on: September 09, 2023, 11:27:22 pm »
Exactly, but I would ask for your help, as I don't know the correct way of asking a feature request.

jamie

  • Hero Member
  • *****
  • Posts: 6786
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #4 on: September 09, 2023, 11:31:53 pm »
Although I know how to hack around that, I feel I must reframe from my offerings. We have some sensitive people around here :o
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12518
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #5 on: September 09, 2023, 11:49:15 pm »
Just added a property FirstDayOfWeek to TCalendardialog and updated the wiki.

As a new feature it will not make it into Laz/fixes, though. If you don't want to wait until Laz v4.0, you can patch your extdlgs unit easily (but make a backup copy first):
  • Open unit extdlgs.pas, it is in the lcl folder of your Lazarus installation.
  • In the interface section, find the declaration of TCalendarDialog, and add "FFirstDayOfWeek: TCalDayOfWeek;" to the private section and "property FirstDayOfWeek: TCalDayOfWeek read FFirstDayOfWeek write FFirstDayOfWeek default dowDefault;" to the published section
Code: Pascal  [Select][+][-]
  1.   TCalendarDialog = class(TExtCommonDialog)
  2.   private
  3.     ...
  4.     FFirstDayOfWeek: TCalDayOfWeek;
  5.     ...
  6.   published
  7.     ...
  8.     property FirstDayOfWeek: TCalDayOfWeek read FFirstDayOfWeek write FFirstDayOfWeek default dowDefault;
  9.     ...
  • Then, in the implementation section of the unit, find "constructor TCalendarDialog.Create(AOwner:TComponent);". Add the line "FirstDayOfWeek := dowDefault;" to this procedure.
Code: Pascal  [Select][+][-]
  1. constructor TCalendarDialog.Create(AOwner: TComponent);
  2. begin
  3.   inherited Create(AOwner);
  4.   ...
  5.   FirstDayOfWeek := dowDefault;
  6.   ...
  • Finally, find the method "function TCalendarDialog.Execute: Boolean;". In the block "with FCalendar do" add the line "FirstDayofWeek := Self.FirstDayOfWeek;"
Code: Pascal  [Select][+][-]
  1. function TCalendarDialog.Execute:boolean;
  2. ...
  3.     FCalendar:=TCalendar.Create(DlgForm);
  4.     with FCalendar do begin
  5.       ...
  6.       FirstDayOfWeek:=Self.FirstDayOfWeek;
  7.       ...
  • Recompile the IDE, and the calendar dialog should have the new property FirstDayOfWeek in the Object Inspector.
« Last Edit: September 10, 2023, 12:54:21 am by wp »

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #6 on: September 10, 2023, 12:33:05 am »
if this was just fpc and not lazarus .....  i'd use

program wokedays;
uses sysutils;
procedure dt; // from /fpc/current/datetime/dt_cr.pas
//const days : array[1..7] of ansistring = ('Sunday ', 'Monday ', 'Tuesday ', 'Wednesday ', 'Thursday ', 'Friday ', 'Saturday ');
const days : array[1..7] of ansistring = ('wokeday ', 'bidenday ', 'trumpday ', 'pelosiday ', 'mconnelday ', 'muskday ', 'zukerday ');
var hour, minute, second, sec100 : word;
    year, month, day : word;
begin
writeln;
decodedate((now - 7.0/24.0), year, month, day); // full date and time for dst
write(days[dayofweek(now - 7.0/24.0)], month, '/', day, '/', year, ' ');
decodetime((now - 7.0/24.0), hour, minute, second, sec100); // dst
writeln(hour, ':', minute, '.', second, '.', sec100);
writeln;
end;

begin
dt;
end.

HexLaden

  • New Member
  • *
  • Posts: 14
Re: How to set FirstDayofWeek in TCalendarDialog?
« Reply #7 on: September 10, 2023, 08:49:58 am »
Patched. Thank you, wp, for the integration of the missing property and for sharing the forecoming implemententation.

TRon

  • Hero Member
  • *****
  • Posts: 3769
Re: [SOLVED] How to set FirstDayofWeek in TCalendarDialog?
« Reply #8 on: September 10, 2023, 01:44:55 pm »
Thank you dsiders for the additional information/corrections (I did not know) and wp for the update/fix.
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018