Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Replacing Julian date in TDBGrid cells

Posted on 1998-12-27
8
Medium Priority
?
298 Views
Last Modified: 2010-04-04
Using Delphi 3, and a TDBGrid, one of the columns/fields displays a date in Julian format (e.g. "145667").

Since my brain cannot convert the Julian value in the DBGrid easily, I am wanting to have some way to display the Julian date as a more user friendly date.

I do NOT want to change the actual value in the linked database table. Instead, I just want the cells in the "Date" column/field to DISPLAY something besides what is in the actual database table.

What is the best way to approach this?  I could have all the Julian dates displayed as "MM-DD-YYYY" in the cells in the "Date" column,  or I could have a popup hint window appear with the converted date when the cursor hovers over a particular date cell.

Any other ideas?

In either case, I don't know how to do either of the above, so any code would likewise be appreciated.
0
Comment
Question by:Monroe406
[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 10

Expert Comment

by:viktornet
ID: 1353302
Hello Monroe!

Would you please tell me what the converted date of 145667 would be??

-Viktor
--Ivanov
0
 

Author Comment

by:Monroe406
ID: 1353303
>> Would you please tell me what the converted date of 145667 would be??

Using my head...it would be approx. November 20, 1998.

I don't want you to get hung up on the date conversion part, however.   I will handle the conversion from Julian back to MM-DD-YY.  All I want is to know how to get change the text that is displayed in the TDBGrid's DATE column.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353304
Try using OnColEnter() and OnColExit()

after that try using dbgrid.MouseCoord() and similar that take the X and Y values to see where you are in the grid, and then display a hint depending on where you are in the Db grid...

Then use       DBGrid1.hint to set the hint and display it... ok i think that will help you do what you want...

-Viktor
--Ivanov
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!

 

Author Comment

by:Monroe406
ID: 1353305
Thanks, but there is too much missing from your suggestion...such as...

+ How to determine WHICH column the user has clicked in.

+ How to determine the contents of the cell (row/column) which the user has clicked in

+ How to place the Hint window over top of the cell that has been clicked in.

These would be necessary for your suggestion to be acceptable.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353306
I tried this one with TStringGrid and it worked... I don't know if it works with the DBGrid...

StringGrid.ShowHint := true; //The ShowHint of the string grid is set to true...

sg = StringGrid

OnMouseMove()
var
  Col, Row : Integer;
begin
  sg.MouseToCell(x, y, Col, Row);
   if (Col > 0) and (Col < sg.ColCount-1) and (Row > 0) and (Row < sg.RowCount-1) then
     sg.Hint := sg.Cells[Col, Row];
end;

Then everything works okay and the contents in the cell is shown as it's suppose to be... try it out with the DB Grid and tell me how it works.. If it doesn't work then reject my answer 'cuz i don't really have much time to work on this.. 10q

Happy New Year!

-Viktor
--Ivanov
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1353307
Hi, Monroe406

Firstly, 145667 is Oct. 26, 1998

Secondly, what you need is to use the OnGetText of the query/table component with you dbgrid connected to.

suppose your query is named MyQuery, and the date field name is myDate, then you should right click myQuery component, select fields editor. If you defined all fields in it, you can find myDate field, select it, and in property list, you can double click OnGetText event in the "events" tab.

then write code like this:

procedure TForm1.myQeuryMyDateGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
         text:=DateTimetoStr(Sender.AsDatetime);
end;

If you didn't define fields in the fields editor, you should do extra works then, any problems, leave me a message;

Regards,
Wang
0
 

Author Comment

by:Monroe406
ID: 1353308

>>I tried this one with TStringGrid and it worked... I don't know if it works
>> with the DBGrid...

Sorry, but it does not work...TDBGrid does NOT have a OnMouseMove event.  :-(

Thanks for your hard work, though.

Wang's comment, however, worked great.
0
 
LVL 4

Accepted Solution

by:
dwwang earned 300 total points
ID: 1353309
Glad that I can help.

Regards,
Wang
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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