Wednesday, March 22, 2006

StrToDateDef, RoundTo and BoolToStr

Delphi has 2 functions not present in FPC:
function StrToDateDef(const S: string; const Default: TDateTime): TDateTime;
function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;

The first one tries to convert String to TDateTime, and if the conversion fails, the result is the value informed at the Default parameter. The second one does banker's rounding to a given precision, informed in power of ten. To round to cents, you need to pass -2, as 10 ^ -2 is 1/100.

There's another function that is present but has different behaviour. It's BoolToStr:
//--- Delphi's BoolToStr
function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
If UseBoolStrs is false (the default), it returns '-1' for true and
'0' for false. If UseBoolStrs is true, it returns the strings 'TRUE'
and 'FALSE'. In Free Pascal it's like this:

//--- in objpas/sysutils/sysstr.inc
function BoolToStr(B: Boolean): string;
begin
If B then
Result:='TRUE'
else
Result:='FALSE';
end;

So a call to BoolStr(true) would return '-1' in Delphi and 'TRUE' in FPC. I don't know if it was pointed before, and I agree that returning 'TRUE' makes a lot of sense, but when porting an application this may lead to trouble. A simple "fix" would be add an extra boolean parameter, with the default value of true:
//--- in objpas/sysutils/sysstr.inc
function BoolToStr(B: Boolean; TF: Boolean = true): string;
begin
If TF then
begin
If B then
Result:='TRUE'
else
Result:='FALSE';
end
else
begin
If B then
Result:='-1'
else
Result:='0';
end;
end;

Of course, some may oppose to this change, as it would be a hack made just in order to keep Delphi compatibility.

Wednesday, March 15, 2006

MDI, qtintf70.dll, launcher... all gone

Several changes has been made in the last few weeks. I also managed to actually convert and open the entire project on Lazarus - as expected, it's not compiling yet. The major changes are:
  • No more MDI: all remaining MDI Forms are now converted to SDI;
  • No more qtintf70.dll dependency: after a complete cleaning, no more QT Units are being used. There were a couple QTypes that were missed in the automated CLX - VCL conversion;
  • No more Launcher: the old launcher checks if there's a newer version in a given web server, and using Indy it downloads it; after that it runs the application. Now the own client app does that (using Synapse), calling an external program only if there IS a new version (the external program, already a Lazarus application, only swaps the downloaded file with the file that were being run).
Now I'll focus in the conversion, in order to actually get the project compiled. I know that get it compiled and get it working are two very different things, but hey, I own the damn company. There's no deadline: it's ready when it's ready!

Sunday, March 05, 2006

Lazarus 0.9.12

This release is based on FPC 2.0.2 and the binary packages now contain many standard packages: RunTimeTypeInfoControls, Printer4Lazarus, CGILaz, CGILazIDE, MemDSLaz, SDFLaz, TurboPowerIPro, JPEGForLazarus, FPCUnitTestRunner, FPCUnitIDE and ProjTemplates.

Here are the full announcement and the download page. Enjoy!