[Lazarus] Challenge of converting a Delphi project

Mattias Gärtner nc-gaertnma at netcologne.de
Mon May 3 14:07:04 CEST 2010


Zitat von Juha Manninen <juha.manninen at phnet.fi>:

> Hi
>
> I have been converting EssModel Delphi program, partly as an exercise and
> partly because it could develop into a useful program or component.
> It is a reverse engineering class diagram tool.
>
> I am facing more problems than expected. This is not related to Delphi
> converter in Lazarus but to the manual editing after it.
>
> First, the code uses a trick. It typecast controls like TForm to a local
> TCrackControl just to reach the protected TControl.OnMouseDown and such.
>
>   type
>     TCrackControl = class(TControl);  // <-- empty local class
>   var
>     found: TControl;
>     cc: TCrackControl;
>
> and later:
>   // 'found' can be TForm or anything.
>   cc:=TCrackControl(found);  // <-- error
>   cc.OnMouseDown := ...
>
> It gives 'RunError(219)', and the whole Lazarus may become unstable.

Do you mean the IDE becomes unstable because of a RunError in a  
debugged program?

RunError are critical. There is something very wrong in the code (e.g.  
dangling poniter, unintialized variable, etc). Please compile with all  
checks.


> The typecast is actually OK because the controls inherit from TControl and
> OnMouseDown is defined there. According to Mattias this system is  
> even used in
> Lazarus itself. In a small test project the same system worked for me, too.
> ???

Just to make this clear:
I discourage such dirty tricks. It is better to fix the used class.


> The program used interfaces heavily, actually in a clever way. I thought they
> cause the above problem and changed the code quite much to get rid of
> interfaces. No difference, it still doesn't work.
>
> Next problem: I noticed there are TActions defined in a DataModule which is
> created in MainForm.OnActivate handler, and the actions are used in form's
> menu and button. I thought it causes problems and I copied everything from
> DataModule to MainForm. I set the actions carefully like they were before and
> now menu items work but open-button does not. The exact same action is
> triggered by menuitem but not by button!
> So, this refactoring didn't solve any problems but created a new one.

Can you create a small example to reproduce the problem?


> And then: before the program closes it writes recent files to registry. It
> gives an error when writing a string, although I can find the "reg.xml" file
> it wrote. The same thing works in my small test project without errors.
>
> All the program's behavior is defined in project file, pascal source code and
> form files. Am I correct?

Yes.
Although the lpi and lpk files are only needed for the compiler parameters.


> So, WHAT CAN CAUSE SUCH PROBLEMS? I have used many many hours already trying
> to solve this.

Maybe the program worked only by accident.


> The program itself is not very important now, I could as well forget it.
> I just feel uncomfortable when there are errors which I can't explain.
> Besides I am supposed to improve Delphi converter but now I am not even able
> to convert a program myself...
>
> My tests happened on Linux, with GTK2 and QT. If someone likes to look at the
> code, please do this:
>
>   $ git clone git://github.com/JuhaManninen/Pascal.git
>
> It is not big.

A lot of files use windows codepages. Maybe the converter could try to  
fix that automatically?


> At least it should be easy to verify the MainForm.OpenButton doesn't work
> while it should, even though the program hasn't done anything yet.


Mattias







More information about the Lazarus mailing list