Thursday, February 15, 2007

Traps of Delphi to Lazarus conversion

There's only a thing worse than a bug difficult to resolve: a bug difficult to find. As an example, i was getting a weird bug in the drawing of VTV. The colors were being painted wrongly and only after a few hours i figured what was going on. See the code below:

with Canvas do
begin
[..]
Brush.Color:=Color;
[..]
end;


Apparently nothing wrong. But the Devil resides in the details. Under Delphi there's no TCanvas.Color while there's in LCL. The result of this code, in Delphi, is that Brush.Color is assigned to TControl.Color. In LCL, Brush.Color is assigned to TCanvas.Color (which in your turn points back to Brush.Color!!).

You can't even say that there's a bug in LCL or in the program. Is just one of traps found while converting Delphi code.

The same occurs with TCanvas.Width/Height (does not exist in Delphi) and TBitmap.Width/Height when used inside compound "with" statements.

6 comments:

Anonymous said...

IMHO these props (missing in Delphi) should be removed from LCL for compatability purpose.

Vincent Snijders said...

It just shows the drawbacks of using with.

Luiz Américo said...

You are right. It can not be considered as a bug.

One of the things i have planned is to evaluate each "with". Imagine the work considering the 37000 lines of code ;-)

Anonymous said...

That's also why they are looking at more awkward "with" constructs for ECMAScript 4:

http://developer.mozilla.org/es4/proposals/reformed_with.html

thierrybo said...

"with" is devil in pascal.

Unknown said...

Hi friends,
Really amazing blog post.I saw and read your blog,This site is useful to
Delphi.I know that it will help me in my own Delphi Blog.I think it may be relevant.
Thank You
http://frankieespinoza.livejournal.com/1181.html