?
Solved

Show date into a TMenu

Posted on 2003-03-22
8
Medium Priority
?
184 Views
Last Modified: 2010-04-04
I wish to show the current date on the right part of my menu. How to do that?
0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 8186461
minTime: TMenuItem;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  mi: MENUITEMINFO;
begin
  mi.cbSize := sizeOf(MENUITEMINFO);
  mi.fMask := MIIM_TYPE;
  mi.fType := MFT_RIGHTJUSTIFY or MFT_STRING;
  mi.dwTypeData := PAnsiChar(TimeToStr(Now));
  mi.cch := strLen(mi.dwTypeData);
  SetMenuItemInfo(MainMenu1.Handle, mniTime.MenuIndex, True, mi);
  DrawMenuBar(Handle);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Timer1Timer(Timer1);
end;

wbr, mo.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 8186620
Where is declared mniTime? I get an error message here.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 8186647
mniTime is the name of your TMenuItem that you want to designate as the one containing the time.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:ginsonic
ID: 8186678
Sorry, I see it now :P, but give me an error.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 8186738
what error?
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8187310
in previous example I provided code to show current time with TTimer, but q was about date :) here will be as complete example as it can be;
I removed some code which disables menu item as it can be done in menu builder and put all code in MainMenu.OnChange event to realign date menu if there is changes in menu (that forces to loose date menu item alignment).

....
type
  TForm1 = class(TForm)
  ...
    MainMenu1: TMainMenu;
    mniTime: TMenuItem;
    procedure MainMenu1Change(Sender: TObject; Source: TMenuItem;
      Rebuild: Boolean);
  ....
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MainMenu1Change(Sender: TObject; Source: TMenuItem;
  Rebuild: Boolean);
var
  mi: MENUITEMINFO;
begin
  mi.cbSize := sizeOf(MENUITEMINFO);
  mi.fMask := MIIM_TYPE;
  mi.fType := MFT_RIGHTJUSTIFY or MFT_STRING;
  mi.dwTypeData := PAnsiChar(FormatDateTime('dd.mm.yyyy', Date));
  mi.cch := strLen(mi.dwTypeData);
  SetMenuItemInfo(MainMenu1.Handle, mniTime.MenuIndex, True, mi);
  DrawMenuBar(MainMenu1.Handle);
end;

wbr, mo.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 8189008
I get an error here:

SetMenuItemInfo(MainMenu1.Handle, mniTime.MenuIndex, True, mi);

"Access violation at address ..... in Project1"
0
 
LVL 9

Accepted Solution

by:
mocarts earned 500 total points
ID: 8189388
you should add in MainMenu1 design time designer a menu item called mniTime.. i.e. mniTime must be created in runtime or in designer. look in debug mode is mniTime assigned?

in runtime you can create item in OnCreate event of form:

procedure TForm1.FormCreate(Sender: TObject);
begin
  mniTime := TMenuItem.Create(MainMenu1);
  MainMenu1.Items.Add(mniTime);
end;

wbr, mo.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question