Recent

Author Topic: Advice on moving from Delphi to Lazarus  (Read 6126 times)

daves001

  • Newbie
  • Posts: 5
Advice on moving from Delphi to Lazarus
« on: May 24, 2021, 01:05:43 pm »
Hi,
Some advice please...
I'm looking at moving from Windows OS to Linux, and from Delphi to Lazarus.  I've programmed in Delphi 7 (hobby only) for many years, designing my own components, etc.  Some of my programs use Windows API calls (like SetWorldTransform) to rotate and zoom objects drawn onto a canvas.  Can anybody tell me if I'll find similar routines in Lazarus/Free Pascal for zoom and rotate of graphics?  Would there be any major stumbling blocks in moving from Delphi to Lazarus?

Thank you

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11447
  • FPC developer.
Re: Advice on moving from Delphi to Lazarus
« Reply #1 on: May 24, 2021, 02:00:07 pm »
Using winapi functions will mostly not port to Linux.   (and usually Linux nowadays means 64-bit)

It can probably be made to work on windows 32-bit. A lot of assembler ridden Delphi 7 code is not even portable to Windows 64-bit.

Start with the easiest target (Windows 32-bit) and then gradually clean up and port. Not all stuff will be possible, and exotic GDI functionality will be hard.


« Last Edit: May 24, 2021, 03:43:27 pm by marcov »

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Advice on moving from Delphi to Lazarus
« Reply #2 on: May 24, 2021, 02:13:38 pm »
Hello daves001,
Welcome to the forum.

Have you decided which Linux you're going to use? I personally use Ubuntu Mate. The reason to use Ubuntu is it has large user base so if I have problem using Linux, answers can be easier to get. I have Nvidia VGA, installing Nvidia driver seems easier on Ubuntu. I prefer Mate, because it is relatively lightweight than other Ubuntu's distributions.

But some years ago, many users reported to have issues installing Lazarus on Ubuntu. Not very sure but it seems the problems have been solved. I haven't tried but many users recommend to use Linux Mint and Manjaro.

If you are good in Delphi, you should have no problem using Lazarus. You should read this:
https://wiki.freepascal.org/Lazarus_For_Delphi_Users

If you want to build cross platform programs, you should not use Windows unit. Alternatively you can use the graphics library that are cross-platform:
https://wiki.freepascal.org/Graphics_libraries

BGRABitmap is relatively easy to use and should offer all the graphics functions you need. Here is the tutorial of BGRABitmap:
https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial

But if performance is important and you like something challenging, you can use OpenGL in Lazarus. Installing TOpenGLControl component in Lazarus is easy:
Lazarus main menu > Package > Install/Uninstall Packages > right panel, select: LazOpenGLContext 0.0.0 > Install selection > Save and rebuild IDE

Here is glSlideshow I made, a cross-platform demo of using OpenGL component:
https://forum.lazarus.freepascal.org/index.php/topic,35313.msg256719.html#msg256719

And this is CATWW, a demo showing how to do image scaling and rotation using BGRABtimap and also image caching for improving the performance:
https://forum.lazarus.freepascal.org/index.php/topic,50989.msg373578.html#msg373578
« Last Edit: May 24, 2021, 02:35:55 pm by Handoko »

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Advice on moving from Delphi to Lazarus
« Reply #3 on: May 24, 2021, 03:06:38 pm »
You are attempting two steps at once, from Windows to Linux, and from Delphi to Lazarus. I guess you will stumble and fall. Do steps one by one.

First convert your project from Delphi to Lazarus, while staying on Windows. Your only task probably is to add the directive {$mode delphi} to your project units. You may have problems with strings: In lazarus a string consists of one-byte entities, in Delphi it consists of two-byte entities; normally this is transparent, but some low-level and system calls can fail. You'll have to convert these strings to WideString, the chars to widechar, and the PChar to PWideChar, plus some issues with UTF8-conversion - all these are solvable.

When you succeeded with the migration you can proceed with the Windows to Linux conversion. Here you must replace all usages of the windows unit by LCLIntf and LCLType, and Messages by LMessages (or simply remove Windows and Messages from the uses clause which are deliberately added by Delphi). If you have windows messages in your code, replace the WM_* messages by LM_Messages. If you are lucky this will be enough. If you are not lucky ask the related questions here. In the worst case, the project will not be portable without major rework.
« Last Edit: May 24, 2021, 07:30:33 pm by wp »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Advice on moving from Delphi to Lazarus
« Reply #4 on: May 24, 2021, 03:50:47 pm »
In lazarus a string consists of one-byte entities, in Delphi it consists of two-byte entities; normally this is transparent, but some low-level and system calls can fail. You'll have to convert these strings to WideString, the chars to widechar, and the PChar to PWideChar, plus some issues with UTF8-conversion - all these are solvable.

He's using Delphi 7; no "unicode-by-default" there! There might be issues with UTF-8 (Lazarus's default, vs. Delphi's Windows codepage) but those can be easily remedied with an appropiate {$codepage xxx} directive.

First step I would take, though, would be to read the manuals (after reading the "Lazarus for Delphians" page); at a minimum peruse the "Programmer's Guide" to learn about the supported directives and other coding (and implementation) issues.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Advice on moving from Delphi to Lazarus
« Reply #5 on: May 24, 2021, 04:12:32 pm »
Do not convert the programm first. Pick one part of interest, make a simpledemo in Delphi and convert it. After this you can look for this part of interest, how work it in Lazarus on windows and later how work it on Linux. If you have one small part working in the demo you have an overview of the caveeats.

If you have windows call for grafik, look for a popular engine, working on all platforms. Convert it first on delphi, after this convert it to Lazarus. See above line :-)
« Last Edit: May 24, 2021, 04:14:27 pm by af0815 »
regards
Andreas

daves001

  • Newbie
  • Posts: 5
Re: Advice on moving from Delphi to Lazarus
« Reply #6 on: June 09, 2021, 07:40:08 pm »
Thanks to all for your wise words...I've started testing graphics with Lazarus under Windows and then moving over to Linux - I've hit some snags already - let's see if we can overcome them!

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11447
  • FPC developer.
Re: Advice on moving from Delphi to Lazarus
« Reply #7 on: June 09, 2021, 10:44:29 pm »
Thanks to all for your wise words...I've started testing graphics with Lazarus under Windows and then moving over to Linux - I've hit some snags already - let's see if we can overcome them!

Another tip: besides that not all GDI functions will have a direct equivalent, most GUI libraries (GTK, QT etc) only allow drawing in the dedicated (on)draw event, not in any event.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Advice on moving from Delphi to Lazarus
« Reply #8 on: June 09, 2021, 11:33:07 pm »
Maybe you could take a look at cross platform pl_graphics32 which you can install directly from Online Package Manager.
Quote
Some of Graphics32 features include: * Fast per-pixel access up to 100 times faster compared to standard TBitmap; * High-performance Bitmap alpha blending (including per-pixel alpha blending); * Pixel, line and polygon antialiasing with sub-pixel accuracy (combined with alpha blending); * Arbitrary polygon transformations and custom fillings; * Bitmap resampling with high quality reconstruction filters (e.g. Lanczos, Cubic, Mitchell); * A unique state-of-the-art rasterization system; * Affine transformations of bitmaps: rotations, scaling, etc with sub-pixel accuracy; * Arbitrary projective transformations of bitmaps; * Arbitrary remapping transformations of bitmaps (e.g. for Warping, Morphing); * Flexible supersampling implementation for maximum sampling quality; * Flicker-free image displaying components with optimized double buffering via advanced MicroTiles? based repaint optimizer; * Multiple customizible easy-to-use overlay layers; * Locking of bitmaps for safe multithreading; * A property editor for RGB and alpha channel loading; * Design-time loading of image formats supported by standard TPicture;

https://github.com/graphics32/graphics32
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user

 

TinyPortal © 2005-2018