Thinkings of a tinker who thinks he’s a thinker


With the release of the new version of Jaledit, I thought of introducing a new feature to all my programs. It’s the typical check for updates. I found that Opera does something similar, where in, when the check for update menu option is clicked, a message is displayed if there are no updates. If there’s an update the web page with the download link for the new version of Opera is is displayed.

I didn’t want a fully automatic update where the update file is downloaded in the background for selfish reasons (I want a page hit ) :-)
So here’s the base spec in my terms

  1. Have a check for updates menu item in the main form and button in the about box form of my Delphi program JALEdit.
  2. Once the user clicks the option, the JALEdit webpage is displayed .
  3. Display message on the page about the status of the update on the top of the page.

My PHP skills = 0, Delphi skills = Advanced

Digging a bit around PHP documentation led to  version_compare, generally used to check PHP versions, but works quite well for program versions as well.

Here’s the code that does the job
$latest = ‘0.5.6′; // define your latest version
$ver = $_GET[’ver’]; // for me this is like a command line argument get whatever is there after ?ver=
if  ($ver)  // Do the check only if the version info is passed  if its just http://jal.sunish.net/jaledit then nothing happens
 {
if (version_compare($latest,$ver) == 1) // there is an update available
print(”<hr/><strong>”.”An update to JALEdit is available. Latest version is :”.$latest.”</strong>”) ;
 // display in bold about update status in between 2 lines
else
print(”<hr/><strong>”.”No update available.You are using the latest version.”.”</strong>”);
print “<hr/>”;
}

What I learnt,

  1. version_compare()  functions compares versions with “.”.
  2. $_GET[’variable’] - function to sort of retrieve command line argument.
  3. . is equivalent to + for string concatenation.
  4. A semicolon is required before the else clause (different from Pascal syntax)

Delphi Code

procedure TfrmSecMain.acncheckUpdatesExecute(Sender: TObject);
var
  tempStr: string;
begin
  tempStr := ‘http://jal.sunish.net/jaledit?ver=’;

  with TJclFileVersionInfo.Create(Application.ExeName) do
  try
    tempStr := tempstr + Format(’%s’, [FileVersion]);
  finally
    Free;
  end;
  ShellExecute(0, ‘open’, pcHAR(tempStr), ”, ”, SW_SHOW);
end;

The Delphi code is pretty straight forward with the JCL function to retrieve the file version from the exe file and that’s passed to the Shellexecute function to do a default browser call.

The PHP code I guess should work with wordpress and any CMS.

 

Excel Rounding Bug and its solution

Oct 15, 2007 Author: Sunish | Filed under: Software, Technology

For many days I was working on a software for automating the daily accounts of our theatre. The software I developed will generate a QIF file that can be imported to Microsoft Money. I used excel automation within delphi to do the printing of DCR (Daily Collection Report). A copy of the DCR is provided to the film distributor. Since quite a lot calculation is involved and the printing has to be formatted I chose excel. It was then that I found that the printed values after the decimal point was not tallying with the Reps report. I knew its’s well known rounding error, but didn’t know its solution. After some googling I found this link http://www.cpearson.com/excel/rounding.htm where a detailed explanation is given. Eventhough the page is a bit dated the solution still works. Just go to Tools,Options and in the Calculation tab you got to check the option of Precision as displayed. Problem solved. Looks like the setting is saved on the open workbook.