BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Including a unit only if Windows system is XP or Vista

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ObjectPascal
View previous topic :: View next topic  
Author Message
Endy
Guest





PostPosted: Tue Feb 20, 2007 8:24 pm    Post subject: Including a unit only if Windows system is XP or Vista Reply with quote



Hello,

We have a program that includes an unit in the project file. This unit
has an initialization part.

The program runs fine on Windows XP machines, but crashes on Windows
98.

Is there a way to say to the program not to include the unit if the
system is Windows 98? Can it be done with conditionals and can you
give an example?

Greetings
Endy
Back to top
Søren Bech Christensen
Guest





PostPosted: Sat Feb 24, 2007 9:12 am    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote



Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the used unit to
differentiate behavior depending on the executing platform.

Best
Søren
Back to top
Sv. Broholm
Guest





PostPosted: Sun Feb 25, 2007 4:43 am    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote



On 24 Feb., 08:29, Søren Bech Christensen <sbc@A...@lodam.DOT.com>
wrote:
Quote:
Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the used unit to
differentiate behavior depending on the executing platform.


No, I disagree.
Include the unit at compiletime.
Test during initialization of the unit if it is executed on a WinNT-
family computer (yes, perform initialization) or a Win9x computer (no,
do not perform initialization).

The following code snip does the trick:

function WinNT : boolean;

Function GetRealDOSver : Word;
Var
Regs : Registers;
Begin
Regs.Ax := $3306;
MsDos( Regs );
GetRealDOSver := Regs.Bx;
End;

begin
If GetRealDOSver = $3205 Then
Begin
{ WinNT / 2000 / XP }
WinNT:=true;
End
Else
Begin
{ DOS / Win9x / WinME }
WinNT:=false;
End;
end;

begin
if WinNT then
PerformInitialization;
end.

Regards
Svend
Back to top
Endy
Guest





PostPosted: Tue Feb 27, 2007 4:48 pm    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote

On 24 feb, 23:43, "Sv. Broholm" <sbroh...@gmail.com> wrote:
Quote:
On 24 Feb., 08:29, Søren Bech Christensen <sbc@A...@lodam.DOT.com
wrote:

Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the usedunitto
differentiate behavior depending on the executing platform.

No, I disagree.
Include theunitat compiletime.
Test during initialization of theunitifit is executed on a WinNT-
family computer (yes, perform initialization) or a Win9x computer (no,
do not perform initialization).

The following code snip does the trick:

function WinNT : boolean;

Function GetRealDOSver : Word;
Var
Regs : Registers;
Begin
Regs.Ax := $3306;
MsDos( Regs );
GetRealDOSver := Regs.Bx;
End;

begin
IfGetRealDOSver = $3205 Then
Begin
{ WinNT / 2000 /XP}
WinNT:=true;
End
Else
Begin
{ DOS / Win9x / WinME }
WinNT:=false;
End;
end;

begin
ifWinNT then
PerformInitialization;
end.

Regards
Svend

Hello Svend,

I tried your code but the problem is my Delphi version doesn't
recognize the "Registers" type. After googling I find out the "Dos"
unit contains this type. But when I add the unit to my uses clause, I
get the error "Dos.dcu" couldn't be found. We use Delphi 7.

Regards
Endy
Back to top
Sv. Broholm
Guest





PostPosted: Wed Feb 28, 2007 5:29 am    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote

On 27 Feb., 11:48, "Endy" <andyimp...@pandora.be> wrote:
Quote:
On 24 feb, 23:43, "Sv. Broholm" <sbroh...@gmail.com> wrote:



On 24 Feb., 08:29, Søren Bech Christensen <sbc@A...@lodam.DOT.com
wrote:

Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the usedunitto
differentiate behavior depending on the executing platform.

No, I disagree.
Include theunitat compiletime.
Test during initialization of theunitifit is executed on a WinNT-
family computer (yes, perform initialization) or a Win9x computer (no,
do not perform initialization).

The following code snip does the trick:

function WinNT : boolean;

Function GetRealDOSver : Word;
Var
Regs : Registers;
Begin
Regs.Ax := $3306;
MsDos( Regs );
GetRealDOSver := Regs.Bx;
End;

begin
IfGetRealDOSver = $3205 Then
Begin
{ WinNT / 2000 /XP}
WinNT:=true;
End
Else
Begin
{ DOS / Win9x / WinME }
WinNT:=false;
End;
end;

begin
ifWinNT then
PerformInitialization;
end.

Regards
Svend

Hello Svend,

I tried your code but the problem is my Delphi version doesn't
recognize the "Registers" type. After googling I find out the "Dos"
unit contains this type. But when I add the unit to my uses clause, I
get the error "Dos.dcu" couldn't be found. We use Delphi 7.

Regards
Endy

My fault - this was correct for up to TP7/BP7.
For Delphi versions the code snip is as follows:

Program Init;
{$APPTYPE CONSOLE}

uses
Windows, SysUtils;

{-- From here and below goes into your unit --}

function IsWinNT: Boolean;
var
OS: TOsVersionInfo;
begin
OS.dwOSVersionInfoSize:=SizeOf(OS);
GetVersionEx(OS);
if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then
Result := True else Result := False;
end;

begin
If IsWinNT Then
writeln('WinNT/2000/XP')
Else
writeln('DOS/Win9x/WinMe');
if isWinNT then
{ PerformInitializationOfUnit };
end.

Hope this helps.

Regards
Svend
Back to top
Endy
Guest





PostPosted: Thu Mar 01, 2007 5:49 pm    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote

On 28 feb, 00:29, "Sv. Broholm" <sbroh...@gmail.com> wrote:
Quote:
On 27 Feb., 11:48, "Endy" <andyimp...@pandora.be> wrote:





On 24 feb, 23:43, "Sv. Broholm" <sbroh...@gmail.com> wrote:

On 24 Feb., 08:29, Søren Bech Christensen <sbc@A...@lodam.DOT.com
wrote:

Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the usedunitto
differentiate behavior depending on the executing platform.

No, I disagree.
Include theunitat compiletime.
Test during initialization of theunitifit is executed on a WinNT-
family computer (yes, perform initialization) or a Win9x computer (no,
do not perform initialization).

The following code snip does the trick:

function WinNT : boolean;

Function GetRealDOSver : Word;
Var
Regs : Registers;
Begin
Regs.Ax := $3306;
MsDos( Regs );
GetRealDOSver := Regs.Bx;
End;

begin
IfGetRealDOSver = $3205 Then
Begin
{ WinNT / 2000 /XP}
WinNT:=true;
End
Else
Begin
{ DOS / Win9x / WinME }
WinNT:=false;
End;
end;

begin
ifWinNT then
PerformInitialization;
end.

Regards
Svend

Hello Svend,

I tried your code but the problem is my Delphi version doesn't
recognize the "Registers" type. After googling I find out the "Dos"
unitcontains this type. But when I add theunitto my uses clause, I
get the error "Dos.dcu" couldn't be found. We use Delphi 7.

Regards
Endy

My fault - this was correct for up to TP7/BP7.
For Delphi versions the code snip is as follows:

Program Init;
{$APPTYPE CONSOLE}

uses
Windows, SysUtils;

{-- From here and below goes into yourunit--}

function IsWinNT: Boolean;
var
OS: TOsVersionInfo;
begin
OS.dwOSVersionInfoSize:=SizeOf(OS);
GetVersionEx(OS);
ifOS.dwPlatformId = VER_PLATFORM_WIN32_NT then
Result := True else Result := False;
end;

begin
IfIsWinNT Then
writeln('WinNT/2000/XP')
Else
writeln('DOS/Win9x/WinMe');
ifisWinNT then
{ PerformInitializationOfUnit };
end.

Hope this helps.

Regards
Svend- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Svend,

Thanks for your help... your solution works fine!

Regards
Endy
Back to top
Søren Bech Christensen
Guest





PostPosted: Thu Mar 08, 2007 1:47 am    Post subject: Re: Including a unit only if Windows system is XP or Vista Reply with quote

Sv. Broholm wrote:

Quote:
On 24 Feb., 08:29, Søren Bech Christensen <sbc@A...@lodam.DOT.com
wrote:
Using units is done at compile-time, so it would make no sense to
platform specifik choices here.

Instead you must edit the initialization part of the used unit to
differentiate behavior depending on the executing platform.


No, I disagree.

No you don't - your suggested solution uses exactly that approach. ;o)
--
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ObjectPascal All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.