Solved

Replacing Julian date in TDBGrid cells

Posted on 1998-12-27
8
289 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
  • 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 100 total points
ID: 1353309
Glad that I can help.

Regards,
Wang
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now