Quantcast
Channel: Programming - Embarcadero Community
Viewing all articles
Browse latest Browse all 167

Calculating how old I am and how many years I have been married - using Delphi and C++Builder

$
0
0

Today is my 65th birthday and my 35th wedding anniversary. How do I remember? I have an app. But before I show the multi-device form, Delphi and C++ code, here are a few computer history items from 1951. Tomorrow, on June 14 (my parents wedding anniversary) in 1951, the U.S. Census Bureau dedicated their UNIVAC computer (they received it in March 1951). The UNIVAC 1 was the first commercially produced electronic digital computer in the United States. UNIVAC (Universal Automatic Computer), was developed by J. Presper Eckert and John Mauchly, who also created the ENIAC computer (the first general-purpose electronic digital computer). UNIVAC weighed 16,000 pounds, had 5,000 vacuum tubes, and benchmarked at 1,000 calculations per second. Also in 1951, Grace Hopper developed A-0 (Arithmetic Language version 0), the first compiler for the UNIVAC 1 computer. In 1951 Geophysical Service Incorporated was renamed as Texas Instruments.

Calculating the number of years since I was born and married (to my wonderful wife Martha) is easy for me. I was married on my 30th birthday. As long as I can remember how old I am and subtract 30, I can remember the number of years that I have been married. And since I was married on my birthday, I can remember my wedding anniversary day. But, for those who need a little help, I have created Delphi and C++Builder multi-device applications using RAD Studio 10.1 Berlin.

The secret is to use the YearsBetween function that is implemented in the System.DateUtils unit.

C++

// C++ source code
#include <fmx.h>
#include <System.DateUtils.hpp>
#pragma hdrstop

#include "ReminderUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    AgeLabel->Text = "Age: "+IntToStr(YearsBetween(Now(),BirthdayCalendar->Date))+" years";
    MarriedLabel->Text = "Married: "+IntToStr(YearsBetween(Now(),AnniversaryCalendar->Date))+" years";
}

Delphi:

// Delphi source code
uses System.DateUtils;

procedure TForm2.Button1Click(Sender: TObject);
begin
  AgeLabel.Text := 'Age: '+IntToStr(YearsBetween(Now(),BirthdayCalendar.Date))+' years';
  MarriedLabel.Text := 'Married: '+IntToStr(YearsBetween(Now(),AnniversaryCalendar.Date))+' years';
end;

 

My multi-device form contains a TToolBar, TButton, a few TLabels and two TCalendar components.

Reminder Form

 

I have used the Object Inspector to preset the Date properties of each TCalendar to my birthday and wedding anniversary day. You can also choose the month, day and year using the TCalendar components at runtime.

Here is the output of the C++ app:

Reminder App Output

 

You can find the sample code for both Delphi and C++ projects on CodeCentral at http://cc.embarcadero.com/item/30575

I want to send out all my love to my wife Martha and to our three daughters Gina, Molly and Emily. I also send huge hugs and love to every developer that I have ever met over my more than 46 years in software engineering. Programming keeps me happy and young. It is an honor and a privilege to be able to work with and be friends with so many great computer industry members. I hope I can keep programming everyday, helping other developers and have this much fun for years to come.

 


Viewing all articles
Browse latest Browse all 167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>