CATWW Version 0.2The performance has been improved. And now user can choose which city to be showed on the clock by clicking on the clock. Because of the size of source code (+images) is now too large to be added on this post, I put the downloadable source code on the first post
https://forum.lazarus.freepascal.org/index.php/topic,50989.0.htmlTo keep it simple, the whole source code is only separated in 3 parts:
- The main form (Mainform.pas), which allow user to change the configuration
- The Clocks (Clocks.pas)
- The DataSync.pas, all the non-graphics calculations should be put in here
How to add the time shift calculation into the code?The time zone lookup and time calculation code should be put in the DataSync.pas.
I quickly generated the time zone data and saved it in
Cities.txt. I use TStringList's LoadFromFile and name-value pair features. It is a quick solution. But if you think it should use a database, just do it and change the related code.
Here is the interface part of DataSync.pas:
unit DataSync;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, Grids, DateUtils;
const
MaxRows = 2;
MaxColumns = 3;
MaxClocks = MaxRows*MaxColumns;
var
CityList: TStringList = nil;
Cities: array[1..MaxClocks] of string = // Empty string means
('', '', '', '', '', ''); // to use system time
procedure LoadCities; // Should be called when program start
procedure FreeAllData; // Should be called when program exit
function GetSystemTimeName: string; // How to name the system time
function GetCityName(Index: integer): string; // Index start from 1
function GetCityTimeZone(Index: Integer): string; // Index start from 1
procedure GetCityTime(Index: Integer; ThisSystem: TTime; var Hour, Minute: Word);
function SelectCity: string; // Show a popup for selecting a city
implementation
type
{ TCityPopup }
TCityPopup = class(TForm)
CityList is used to store the data loaded from Cities.txt. And
Cities is the data that stores the user selected city for each of the clock. The code for loading the data should be put in
LoadCities and
FreeAllData is for freeing all the in-memory objects.
GetSystemTimeName is the name for the clock that using the computer time. Change the return string to whatever you think better.
I do not have solution for the time zone calculation, I quickly created a fake time calculation, which is not correct. It is in
GetCityTime.
GetCityName is used for converting the loaded data for the city name and
GetCityTimeZone are the data for saved time zone. The code of GetCityTime, GetCityName and GetCityTimeZone need to be changed.
SelectCity will be called if user want to change the city for the clock (which can be done by clicking the clock). It will runtimely create a popup based on
TCityPopup class. I tested the TCityPopup on a separated code, the performance was still okay even the item count has reached 300.000. It uses TStringGrid for the drawing but data is maintained separately.
Performance improvementThe code now uses cache system and multi-resolution images, which generated at runtime. It run pretty good on my test, although I wish resizing the clocks can be faster.
Please test it.
Do it run correctly on different environment?
And do you think the performance is acceptable?
Any suggestions and criticisms are welcome.
The source code can be downloaded here:
https://forum.lazarus.freepascal.org/index.php/topic,50989.0.html