Recent

Author Topic: Transporting Delphi 1.0 forms to Lazarus  (Read 13930 times)

texasyen

  • New Member
  • *
  • Posts: 16
Transporting Delphi 1.0 forms to Lazarus
« on: May 09, 2012, 08:19:08 pm »
Lazarus version: 0.9.30.4; FPC version: 2.6.0-win32

There are certain components that I've used (such as TTable, TTabbedNoteBook) that do not translate into Lazarus. The unit, in which the form is defined, does translate. Now, I have a unit without a form.

For small projects (think 1 form), that doesn't matter. I recreate the form in Lazarus and cut-and-past the appropriate code from the original unit to the Lazarus unit. A hassle but, hey, it gets the job done. Now I'm confronted with translating a very big project (think about 10 forms).

Some forms translate, some forms do not. All units translate. What can I do to quickly (let's define "quickly" to mean within a day) reattach a form to the now-formless unit? A 10-day translation from Delphi to Lazarus, while "soul deflating," is ... (and let's just leave it at that!)

Anybody with any good (I'll even take bad right about now) suggestions on translating "untranslable" forms into Lazarus will be much appreciated. Also, and perhaps more importantly, any suggestions on how to create a form and attach that form into another unit?

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #1 on: May 09, 2012, 08:53:28 pm »
Have never tried it with Delphi1 forms but Lazarus works with .dfm forms since at least a year. The .dfm forms have to be save in text format. I have several Lazarus projects that use .dfm forms from D6. It isn't publicised a lot because the downside is that you can't visualise the form in the Lazarus IDE. So any changes to the forms to adapt to linux or OSX layout differences have to be made in Delphi. If you just want to port the Delphi project to Lazarus for its multi-platform capabilities and don't need to change the layout a lot then this is an option.

For one of my projects the Win32 development had to continue on Delphi and the port to the other platforms with Lazarus was done in parallel. Some Delphi components use properties that are not defined in Lazarus which will result in run time errors about undefined properties when using dfm forms. You can remove these properties from the dfm files but every time Delphi saves the form, they'll be back. A trick to discard these properties is to add an initialization section to the unit as in the following example:
Code: [Select]
uses ...
 {$IFDEF FPC}
  LResources,
 {$ENDIF}
....
{$IFDEF FPC}
initialization
PropertiesToSkip.Add(TForm,'TextHeight','','');
PropertiesToSkip.Add(TForm,'DesignSize','','');
PropertiesToSkip.Add(TPanel,'DesignSize','','');
PropertiesToSkip.Add(TButton,'WordWrap','','');
{$ENDIF}
end.
This way you can create units that can be compiled simultaneously in Delphi and Lazarus :)
« Last Edit: May 09, 2012, 09:13:59 pm by ludob »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #2 on: May 09, 2012, 10:09:03 pm »
I guess you tried the Delphi converter in Lazarus. Does it not work for your project?
It should be able to convert also the old Delphi binary form file format.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

texasyen

  • New Member
  • *
  • Posts: 16
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #3 on: May 09, 2012, 10:51:19 pm »
ludob--It seems that, since you're giving me a work around, translating Delphi to Lazarus is not going to be an easy experience.

juhaManninen--Yes, I've "Convert Delphi project to Lazarus project" under the Tools menu and I've "Convert binary DFM to text LFM". I found the *.LFM's. So I have in one window, say URate.LFM and in another window URate.PAS. In URate.PAS, I toggle to the form and nothing happens. So, what should I do with the *.LFM files? Is there a way to convert the text.LFM back to Lazarus's equivalent for Delphi's DFM?

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #4 on: May 10, 2012, 12:01:52 am »
juhaManninen--Yes, I've "Convert Delphi project to Lazarus project" under the Tools menu and I've "Convert binary DFM to text LFM". I found the *.LFM's. So I have in one window, say URate.LFM and in another window URate.PAS. In URate.PAS, I toggle to the form and nothing happens. So, what should I do with the *.LFM files?

"Convert Delphi project to Lazarus project" should do all the necessary steps for both pascal and form files. It is explained here:
  http://wiki.lazarus.freepascal.org/Delphi_Converter_in_Lazarus

Does the converter give errors and stop? If yes then please create a bug report with an example project.

Quote
Is there a way to convert the text.LFM back to Lazarus's equivalent for Delphi's DFM?

Yes, just rename it to .dfm. The file format is the same.
There are problems though, as ludob explained. Some properties differ or are missing. Either Delphi or Lazarus complains and removes those properties. Thus it is difficult to maintain the same .dfm form file between Delphi and Lazarus. Typically people maintain the same pascal source (.pas) but separate form files (.dfm and .lfm).
This is also the original reason to have a different filename suffix (I guess).
You can use IFDEFs for differences in .pas files but not in .dfm files.

BTW, the final success in conversion depends on components used and Windows specific technologies etc, but your conversions seems to end before those problems.


Regards,
Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #5 on: May 10, 2012, 07:37:53 am »
Quote
ludob--It seems that, since you're giving me a work around, translating Delphi to Lazarus is not going to be an easy experience.
No, I wanted to propose an alternative to translating forms in case you don't need to edit the forms in Lazarus or when the development continues in Delphi and Lazarus is used to port to other platforms.
When the translation tools fail, the probability is high that this technique is not working either.

It would be helpful to attach a unit + form that the tools fail to  translate. You can empty the implmentation part if that is sensitive.

texasyen

  • New Member
  • *
  • Posts: 16
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #6 on: May 11, 2012, 11:52:41 pm »
ludob: Okay, here's a unit that did compile but the form did not. I also converted the DFM form itself. All are attached. I hope they come through and you can do something with them.

The problem with this form is that it contains a TTabbednotebook which does not have a Lazarus equivalent. The closest thing that I've found is a TPageControl. It also has a TQuery, TDataSource, TMenuItem.

I found a work around by creating a new unit/form, dropping a TPageControl and cutting/pasting the Delphi components into the TPageControl's TTabSheet. CLicking on the proper Event handlers and cutting/pasting code into the handlers. A hassle but it was doable.

But for the future: If it was because of something stupid that I did, I hope you can get my head on straight.

Thanks for your help.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #7 on: May 12, 2012, 11:48:39 am »
It requires a little bit of fiddling but it is definitely faster than re-creating the form from scratch. Here is the procedure I used:
- Convert Delphi unit to Lazarus unit
- Click Edit Type Replacements
- Add TTabbedNotebook | TPageControl 
- Add TTabPage | t:TTabSheet
- Add TQuery | TSQLQuery
- Start Conversion
- Edit the lfm file. TTabPage is an unnamed object which we replaced by t:TTabSheet and we have created several tab sheets with the same name "t".  Search for "t:TTabSheet" and replace "t" with an unique name of your choice.
- Open the unit. You'll get some unknown properties which you can safely Continue Loading.

The TQuery | TSQLQuery replacement only works if you have installed the sqldblaz package.

The result is attached.

« Last Edit: May 12, 2012, 12:49:35 pm by ludob »

texasyen

  • New Member
  • *
  • Posts: 16
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #8 on: May 12, 2012, 04:33:14 pm »
Yes I've got sqldblaz installed.

You've taken some time with me and I appreciate that. Thanks ludob. I'm going over what you sent.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #9 on: May 12, 2012, 09:05:24 pm »
- Add TTabbedNotebook | TPageControl 
- Add TTabPage | t:TTabSheet
- Add TQuery | TSQLQuery

I added those types as defaults to Converter/ConvertSettings:

  MapReplacement('TTabbedNotebook',   'TPageControl');
  MapReplacement('TTabPage',          'ts$autoinc:TTabSheet');
  MapReplacement('TQuery',            'TSQLQuery');
  MapReplacement('TADOQuery',         'TSQLQuery');

The "ts$autoinc" syntax does not work yet but I will add support for it.
What about the DB connection components?

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #10 on: May 13, 2012, 10:09:04 am »
I added those types as defaults to Converter/ConvertSettings:

  MapReplacement('TTabbedNotebook',   'TPageControl');
  MapReplacement('TTabPage',          'ts$autoinc:TTabSheet');
  MapReplacement('TQuery',            'TSQLQuery');
  MapReplacement('TADOQuery',         'TSQLQuery');

The "ts$autoinc" syntax does not work yet but I will add support for it.
What about the DB connection components?
Great!

The TTabbedNotebook and TTabPage is the most important since failing to translate them results in the loss of all the child controls.

DB connection components are less critical. Delphi has a miriad of architectures and components. If the main purpose of the translator is to not loose components and give the best functional match then you can add the following:

'TSQLConnection','TSQLConnector'
'TSQLDataset','TSQLQuery'
'TSQLStoredProc','TSQLQuery'
'TSQLTable','TSQLQuery'
'TSQLClientDataSet','TSQLConnector'

'TTable','TSQLQuery'
'TStoredProc','TSQLQuery'
'TUpdateSQL','TSQLQuery'
'TDatabase','TSQLConnector'
'TBDEClientDataSet','TSQLConnector'

'TADOConnection','TSQLConnector'
'TADOCommand','TSQLQuery'
'TADODataSet','TSQLQuery'
'TADOTable','TSQLQuery'
'TADOStoredProc','TSQLQuery'

'TIBTable','TSQLQuery'
'TIBQuery','TSQLQuery'
'TIBStoredProc','TSQLQuery'
'TIBDatabase','TIBConnection'
'TIBTransaction','TSQLTransaction'
'TIBUpdateSQL','TSQLQuery'
'TIBDataSet','TSQLQuery'
'TIBSQL','TSQLQuery'
'TIBClientDataSet','TIBConnection'


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #11 on: May 13, 2012, 07:42:49 pm »
TTabbedNotebook is now properly converted to TTabPage. This is a nice feature really (even if I say it myself). Please test with Lazarus trunk.

I also added the DB components to replace but I didn't really test yet. It may need replacing used units in Delphi source with some other unit names. Does anyone know which ones?
The converter does not yet get the unit name of a component automatically.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #12 on: May 13, 2012, 08:48:01 pm »
Quote
This is a nice feature really (even if I say it myself).
Thank you for the compliment  ;D
Quote
I also added the DB components to replace but I didn't really test yet. It may need replacing used units in Delphi source with some other unit names. Does anyone know which ones?
The converter does not yet get the unit name of a component automatically.
Lazarus/fpc:
TIBConnection unit IBConnection
TSQLQuery, TSQLConnector,TSQLTransaction unit sqldb

Delphi
TSQLConnection, TSQLDataSet, TSQLQuery, TSQLStoredProc, TSQLTable unit SqlExpr
TSQLClientDataSet unit DBLocalS

TTable, TQuery, TStoredProc, TDatabase, TUpdateSQL unit DBTables
TBDEClientDataSet unit DBLocalB

TADOConnection, TADOCommand, TADODataSet, TADOTable, TADOQuery, TADOStoredProc unit ADODB

TIBTable unit IBTable
TIBQuery unit IBQuery
TIBStoredProc unit IBStoredProc
TIBDatabase,TIBTransaction   unit IBDatabase
TIBUpdateSQL unit IBUpdateSQL
TIBDataSet unit IBCustomDataSet
TIBSQL unit IBSQL
TIBClientDataSet unit DBLocalI

So all these Delphi units translate to sqldb except for DBLocalI that translates to IBConnection. Don't know if duplicate units are already removed in the tool.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Transporting Delphi 1.0 forms to Lazarus
« Reply #13 on: May 13, 2012, 09:53:55 pm »
So all these Delphi units translate to sqldb except for DBLocalI that translates to IBConnection. Don't know if duplicate units are already removed in the tool.

Thanks! I added the unit name replacements. The converter can deal with identical unit names, no problem.
I have not much time to test now, at least for one week. Feedback is welcome.

The converter is different from other Lazarus code because it is doing fuzzy things for the code and success is not guaranteed. It can never convert all available Delphi code.
There hasn't been issue reports about the converter for some time, maybe because its form file conversion was broken for a long time and people waited it to be fixed.
Now the basic conversion works well but a more advanced code analysis is still not possible with the current parser.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018