Recent

Author Topic: Uses Windows Problem (solved)  (Read 16191 times)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Uses Windows Problem (solved)
« on: March 31, 2013, 09:56:22 pm »
Code: [Select]
unit Unit1;

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

uses
{$IFNDEF FPC}
  Windows,  //[b]Whats the use of these Windows line here? <Im in Windows XP Delphi 7?> [/b]
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
  (Windows,)Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst, ComCtrls;
  //Many ERRORS come out without (Windows,) [before Messages,]


When Lazarus converter convert my Delphi project, the Windows clause was not included(Windows,) Messages, SysUtils,...,...,..;
Whats the meaning of this?


This errors without the (Windows,)
Code: [Select]
hTest := CreateFile(PChar( Format('%s\_x%d.tmp', [SharedPath, GetTickCount])),
  GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);   


Does that mean that I could not compile it in MAC Lion OS?

thanks
« Last Edit: April 01, 2013, 10:24:56 pm by xenblaise »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Uses Windows Problem
« Reply #1 on: March 31, 2013, 10:39:03 pm »
CreateFile() is WinAPI function, you have to replace its functionality with something else. You can do crossplatform file handling with for example AssignFile() or TFileStream.

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Uses Windows Problem
« Reply #2 on: March 31, 2013, 11:06:20 pm »
Ok, so do you meant if I removed the (Windows,) clause will ERROR mostly if it depends in Windows WinAPI?  :o
Code: [Select]
{$ENDIF}
  (Windows,)Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst, ComCtrls;



So this line is not for Windows at all, its from Lazarus Windows?
Code: [Select]
{$IFNDEF FPC}
  Windows,  //[b]Whats the use of these Windows line here?[/b]
{$ELSE}

So, I can't use this code in MAC OS Lion!?
Code: [Select]
hTest := CreateFile(PChar( Format('%s\_x%d.tmp', [SharedPath, GetTickCount])),
  GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);   

Can use only FileCreate! :-X
Confirmed.
thanks :-[
« Last Edit: March 31, 2013, 11:42:15 pm by xenblaise »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: Uses Windows Problem
« Reply #3 on: April 01, 2013, 12:23:53 am »
Ok, so do you meant if I removed the (Windows,) clause will ERROR mostly if it depends in Windows WinAPI?  :o

Obviously yes. Windows unit is about WinAPI.
You selected "Cross Platform" and "Support Delphi" in converter. Windows unit can be used only in Windows.
Some of the WinAPI is ported, units LCLIntf and LCLType are added for that.

Quote
So this line is not for Windows at all, its from Lazarus Windows?
Code: [Select]
{$IFNDEF FPC}
  Windows,  //[b]Whats the use of these Windows line here?[/b]
{$ELSE}

No, it is for Delphi Windows.

Quote
Can use only FileCreate! :-X

How did you use the converter?
CreateFile is converted automatically to FileCreate. See the converter settings dialog.

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

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Uses Windows Problem
« Reply #4 on: April 01, 2013, 01:02:39 am »
I finally understand now  :)

Ok, where can I find a list of Units of Lazarus, so if I'm in windows and preparing a code for mac compilation, I will be able to notice what are the units I will use and not use.

LCLIntf and LCLType?
What are the others, where can I find them?

thanks :D

ok, I think it can be found in this folders :-[  ?
C:\lazarus\lcl\
« Last Edit: April 01, 2013, 01:11:18 am by xenblaise »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: Uses Windows Problem
« Reply #5 on: April 01, 2013, 10:14:47 am »
Ok, where can I find a list of Units of Lazarus, so if I'm in windows and preparing a code for mac compilation, I will be able to notice what are the units I will use and not use.

LCLIntf and LCLType?
What are the others, where can I find them?

ok, I think it can be found in this folders :-[  ?
C:\lazarus\lcl\

Yes, you can use anything from lcl directory.
No platform specific units are added automatically when you design with Lazarus. Your app will be cross-platform by default.

When porting from Delphi, "Windows" unit is often the only windows specific unit to worry about.
Sometimes there are also external components/classes that depend heavily on Windows and cannot be ported.
Your app will be difficult to port if it uses lots of WinAPI or OLE automation etc., or it uses those external components.

I recommend using Linux to test your code. You can install Linux also in a virtual machine.
If your code works on Linux, it has a big chance to work on OS/X, too.

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

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: Uses Windows Problem
« Reply #6 on: April 01, 2013, 03:54:48 pm »
Note that FILE_FLAG_DELETE_ON_CLOSE is a windows specific flag, which is likely not supported on other platforms. You'll probably need to delete them manually

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Uses Windows Problem
« Reply #7 on: April 01, 2013, 05:21:09 pm »
Quote
So this line is not for Windows at all, its from Lazarus Windows?
Code: [Select]
{$IFNDEF FPC}
  Windows,  //[b]Whats the use of these Windows line here?[/b]
{$ELSE}

No, it is for Delphi Windows.


But its not working on my windows XP Lazarus 1.08
It will only accept my WinAPi IF Ill put the Windows clause after the {$ENDIF}
Code: [Select]
uses
{$IFNDEF FPC}
  Windows,[b] //SO THIS IS NOT WORKING? but it is said it is for WINDOWS OS with WinAPI functions[/b]
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
 
[b] (Windows,) [/b]          Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst, ComCtrls;
  //Many ERRORS(winapi) come out without [b](Windows,) [/b]

Why is that?


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: Uses Windows Problem
« Reply #8 on: April 01, 2013, 05:39:19 pm »
But its not working on my windows XP Lazarus 1.08

Maybe your brain is over-loaded with too much info now.
Again, it is for Delphi. Then "FPC" is not defined.

One question is, do you need to support Delphi in your code?
If not, then many things become easier.

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

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Uses Windows Problem
« Reply #9 on: April 01, 2013, 09:33:44 pm »
uses
{$IFNDEF FPC}
  Windows, //Does not work
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
Windows, ..... <this works

Really Im not joking!

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: Uses Windows Problem
« Reply #10 on: April 01, 2013, 09:56:02 pm »
Really Im not joking!

Me neither. It is for Delphi!
If you don't need to support Delphi then you don't need the IFDEF at all.

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

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Uses Windows Problem
« Reply #11 on: April 01, 2013, 10:03:15 pm »
uses
{$IFNDEF FPC} // "If not defined FPC, then include following lines". If you compile this on Lazarus, obviously FPC is defined, and everything after this is ignored until that ELSE.
  Windows,
{$ELSE} // "Here comes units that are compiled when FPC is defined."
  LCLIntf, LCLType, LMessages,
{$ENDIF}
// And finally units that are ALWAYS included:
Windows, .....

And of course, if you compile the unit with Delphi, then FPC is not defined...

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Uses Windows Problem
« Reply #12 on: April 01, 2013, 10:23:46 pm »
uses
{$IFNDEF FPC} // "If not defined FPC, then include following lines". If you compile this on Lazarus, obviously FPC is defined, and everything after this is ignored until that ELSE.
  Windows,
{$ELSE} // "Here comes units that are compiled when FPC is defined."
  LCLIntf, LCLType, LMessages,
{$ENDIF}
// And finally units that are ALWAYS included:
Windows, .....

And of course, if you compile the unit with Delphi, then FPC is not defined...


So, the units here in Lazarus can be compiled in Delphi also! (Its been 1year plus that I did not do programming with Lazarus or Delphi)
and
I understand, I was lost with {IFNDEF FPC} and {IFDEF FPC}, I read them the same,  JuhaManninen was correct I've got a tired eyes.
thanks to both of you. :)

 

TinyPortal © 2005-2018