Recent

Author Topic: Porting from Delphi to Lazarus  (Read 15208 times)

vini7

  • New Member
  • *
  • Posts: 13
Porting from Delphi to Lazarus
« on: November 01, 2007, 11:05:29 am »
Hi

I am new to Lazarus..
I am poerting delphi code to lazarus.

I am getting following error:
1) SetVolumeLabel('c:\', VolumeName);
error: illegal expression.

2)Hint: Local variable does not seem to be initilized

3)Error: Identifier not found "GetUserName"
4)Error: Identifier not found "SetVolumeLabel"
5)Error: Identifier not found "ExitWindowsEX"
6)Error: Identifier not found "Ewx_Force"
7)Error: Identifier not found "Ewx_Reboot"
8)Error: Identifier not found "ShellExecute"
9)Error: Identifier not found "ShellExecute"
10) Warning: Local variable "FileHandle" does not seem to be initialized
11)Error: Identifier not found "GetVolumeInformation"


Why I am getting these error?? how to resolve these errors???

Please help..

vini7

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
RE: Porting from Delphi to Lazarus
« Reply #1 on: November 01, 2007, 12:32:06 pm »
These are Winapi functions.
It might work if you include "Windows" in the uses clause, but then your software will only work on Windows, not Linux, MacOS etc.

vini7

  • New Member
  • *
  • Posts: 13
RE: Porting from Delphi to Lazarus
« Reply #2 on: November 01, 2007, 12:45:25 pm »
is there any other alternative???

what about getUserName and setVolumeLabel?????

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
RE: Porting from Delphi to Lazarus
« Reply #3 on: November 01, 2007, 01:08:53 pm »
These are highly system dependent things.
The native Linux file system has nothing like a VolumeLabel afaik.
On Linux, you get the user like getenvironmentvariable('USER');
For Reboot and such things, you'll need root privileges on Linux afaik.
You cannot "simply" recompile your code for other systems with this level of system dependency.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Porting from Delphi to Lazarus
« Reply #4 on: November 01, 2007, 01:14:36 pm »
I don't have any alternatives for GetUserName, SetVolumeLabel, ExitWindowsEX, Ewx_Force, Ewx_Reboot, or GetVolumeInformation. But for ShellExecute there are 2 alternatives. Either use TProcess from unit Process, or ExecuteProcess from SysUtils. Read this for further information. Perhaps for GetUserName, you can see if there's any related function in fcl-registry. Can you tell what actually ExitWindowsEX, Ewx_Force, Ewx_Reboot do?

vini7

  • New Member
  • *
  • Posts: 13
RE: Porting from Delphi to Lazarus
« Reply #5 on: November 01, 2007, 01:21:41 pm »
but in my delphi code I am using these api and I want same type of features in linux based lazarus code.... So there must be some equivalent functions.... do u know or hoe to use these????

I think these are the main critical part while porting Delphi code to Lazarus code...

please explain me in more detail

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
RE: Porting from Delphi to Lazarus
« Reply #6 on: November 01, 2007, 01:44:39 pm »
You should try to understand what your code does, why it does it and which alternatives there are.
You can't change things like VolumLabel if there is no VolumeLabel.
Shutting down or Rebooting the System is most likely not necessary for a Linux Application.
How to execute external programs in a cross-platform way is described here http://wiki.lazarus.freepascal.org/Executing_External_Programs

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: RE: Porting from Delphi to Lazarus
« Reply #7 on: November 01, 2007, 03:57:27 pm »
Quote from: "vini7"
but in my delphi code I am using these api and I want same type of features in linux based lazarus code.... So there must be some equivalent functions.... do u know or hoe to use these????

I think these are the main critical part while porting Delphi code to Lazarus code...

please explain me in more detail


Delphi programmers often treat the Win API functions as part of the Delphi runtime. This is fine if the program will only be run on Windows, but not such a good habit if there's any chance the program will need to someday run on other platforms.

The Lazarus LCLIntf units supports some of the Win API functions where it makes sense and where there's a corresponding function or way to emulate it on all platforms.

Theo is right - you really need to step back and think about what your program is trying to do in a general sense. You know what it's trying to do in a specific sense (i.e., it's trying to call a number of Windows API functions). You'll also probably have to learn at least a little about your new target platforms (Linux, Mac OS?). Once you have this level of understanding of both your program and the target platforms, you can decide: can the code be rewritten to emulate what it does on Windows? can the code simply be eliminated? is there a simpler way to achieve what the code is doing on Windows?

Remember that the Free Pascal RTL has an extremely rich set of functions, both general (available on all platforms, for example everything in the SysUtils unit) and specific (Unix, BaseUnix units). If you spend some time investigating these units (see the .pdf files!) you may discover that you can do the same thing at a higher-level rather than at the OS API level.

Thanks.

-Phil

vini7

  • New Member
  • *
  • Posts: 13
Porting from Delphi to Lazarus
« Reply #8 on: November 02, 2007, 07:27:27 am »
thanks for ur valuable advice.. i ll chk it out its requirment

vini7

  • New Member
  • *
  • Posts: 13
Porting from Delphi to Lazarus
« Reply #9 on: November 02, 2007, 11:16:21 am »
I have resolved all windows based APIs.also used Tprocess for executing shell.

Now I am getting "unable to open applicarion.RES file"

what is res file?(i guess it is resource file)
then how to convert this delphi file to lazarus???

please help...


Thanks & Regards

vini7

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Porting from Delphi to Lazarus
« Reply #10 on: November 02, 2007, 11:28:42 am »
I think you don't need it. Just remove the line in you project file.
Read also:
http://wiki.lazarus.freepascal.org/Code_Conversion_Guide

Phil

  • Hero Member
  • *****
  • Posts: 2737
Porting from Delphi to Lazarus
« Reply #11 on: November 02, 2007, 02:19:17 pm »
Quote from: "vini7"
Now I am getting "unable to open applicarion.RES file"

what is res file?(i guess it is resource file)
then how to convert this delphi file to lazarus???


With Delphi the .res file typically contains the application's icon and version resource. You can exclude it from compiling on Linux and OS X:

{$IFDEF MSWINDOWS}
{$R *.res}
{$ENDIF}

Thanks.

-Phil

 

TinyPortal © 2005-2018