Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How can I eliminate these warnings in Delphi 7 which did not appear in Delphi 5.

945 views
Skip to first unread message

Peter Williams

unread,
Aug 5, 2006, 1:35:50 PM8/5/06
to

Hello All (again)

Peter Williams wrote:

>
> Hello All,
>
> I would like help in removing these warnings from some Delphi 7
> source code which I have migrated from Delphi 5. Note also please,
> that although I want to remove these warnings from Delphi 7 source
> code, I still want it to be compilable using Delphi 5. :-)))
>
> Warnings in MyIniFiles.pas using Delphi 7. These warnings did not
> appear in Delphi 5.
>
> from File MyIniFile.pas ...
>
[big snip]

I have now uploaded the file: MyIniFile.pas to newsgroup
borland.public.attachments. See message with same subject as this one
(without the leading "Re: ").

--
Regards,
PEW ;-)
Delete SILLY BOY to get email address.

Sandy Bay, Hobart, Tas, AU.

Peter Williams

unread,
Aug 5, 2006, 1:22:50 PM8/5/06
to

Hello All,

I would like help in removing these warnings from some Delphi 7 source
code which I have migrated from Delphi 5. Note also please, that
although I want to remove these warnings from Delphi 7 source code, I
still want it to be compilable using Delphi 5. :-)))

Warnings in MyIniFiles.pas using Delphi 7. These warnings did not
appear in Delphi 5.

from File MyIniFile.pas ...


{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,99 Inprise Corporation }
{ }
{*******************************************************}

unit MyIniFiles;

{$R-,T-,H+,X+}

// MyIniFiles -- modified version of IniFiles.pas
// by Peter E. Williams
// 18 Dec 2001
// 2 new public procedures added:
// MyReadBool, MyWriteBool

function TMyIniFile.ReadString(const Section, Ident, Default: string):
string;
var
Buffer: array[0..2047] of Char;
begin
// next line in line #307
SetString(Result, Buffer, GetPrivateProfileString(PChar(Section),
PChar(Ident), PChar(Default), Buffer, SizeOf(Buffer),
PChar(FFileName)));
end;

[Warning] MyIniFiles.pas(307): Unsafe type 'PChar'
[Warning] MyIniFiles.pas(308): Unsafe type 'PChar'
[Warning] MyIniFiles.pas(308): Unsafe type 'PChar'

etc.

procedure TMyIniFile.WriteString(const Section, Ident, Value: string);
begin
if not WritePrivateProfileString(PChar(Section), PChar(Ident),
PChar(Value), PChar(FFileName)) then
// next line is # 315
raise Exception.CreateResFmt(@SIniFileWriteError, [FileName]);
end;

[Warning] MyIniFiles.pas(315): Unsafe code '@ operator'

procedure TMyIniFile.ReadSections(Strings: TStrings);
const
BufSize = 16384;
var
Buffer, P: PChar;
begin
// next line is # 324
GetMem(Buffer, BufSize);
try
//...

[Warning] MyIniFiles.pas(324): Unsafe code 'GetMem'
[Warning] MyIniFiles.pas(324): Unsafe type 'Buffer: PAnsiChar'

---- different file now (uFixedWidthFonts.pas)

type
// these lines "borrowed" from SDL.pas
SInt16 = smallint;
UInt16 = word;

PSDL_Rect = ^TSDL_Rect;
TSDL_Rect = record
x, y: SInt16;
w, h: UInt16;
end;
// end lines from SDL

// next line is #24
PFixedFont = ^TFixedFont;
TFixedFont = object

[Warning] uFixedWidthFonts.pas(24): Unsafe type 'TFixedFont: old style
object'

---- different file now (MainUnit.pas)

const
...
soundfx_filename_fly_move = 'fly_movex.wav';
...

procedure TMainForm.move_fly_sound_effect;
var
tempstr: string;
begin
tempstr := soundfx_filename_fly_move;
tempstr[9] := inttostr(random(3) + 1)[1];
play_wave(tempstr);
end;

[Warning] MainUnit.pas(747): Unsafe code 'String index to var param'

Dennis Passmore

unread,
Aug 5, 2006, 5:10:16 PM8/5/06
to
>> from File MyIniFile.pas ...

The easiest way is to just add the compiler switches as shown to the top of the MyIniFile.pas unit.

{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}

Borland added these D7 compiler checks to help ensure that your code maybe compatible with .NET when
needed.
Dennis Passmore

"If you cannot conceive the idea you
will never achieve the desired results"

Peter Williams

unread,
Aug 5, 2006, 5:37:23 PM8/5/06
to
Peter Williams wrote:

>
> Hello All,
>
> I would like help in removing these warnings from some Delphi 7
> source code which I have migrated from Delphi 5. Note also please,
> that although I want to remove these warnings from Delphi 7 source
> code, I still want it to be compilable using Delphi 5. :-)))
>
> Warnings in MyIniFiles.pas using Delphi 7. These warnings did not
> appear in Delphi 5.
>
> from File MyIniFile.pas ...
>
>

[snip]

> [Warning] MyIniFiles.pas(307): Unsafe type 'PChar'

Dennis Passmore has given me and answer to this. Thank you, Dennis.

==================================

what do I do about this warning???

> type
> // these lines "borrowed" from SDL.pas
> SInt16 = smallint;
> UInt16 = word;
>
> PSDL_Rect = ^TSDL_Rect;
> TSDL_Rect = record
> x, y: SInt16;
> w, h: UInt16;
> end;
> // end lines from SDL
>
> // next line is #24
> PFixedFont = ^TFixedFont;
> TFixedFont = object
>

> [Warning] uFixedWidthFonts.pas(24): Unsafe type 'TFixedFont: old style
> object'

===================================

and this what about this warning???

> const
> ...
> soundfx_filename_fly_move = 'fly_movex.wav';
> ...
>
> procedure TMainForm.move_fly_sound_effect;
> var
> tempstr: string;
> begin
> tempstr := soundfx_filename_fly_move;
> tempstr[9] := inttostr(random(3) + 1)[1];
> play_wave(tempstr);
> end;
>
> [Warning] MainUnit.pas(747): Unsafe code 'String index to var param'

I will appreciate anyone assistance. :-)))

C-H

unread,
Aug 5, 2006, 7:05:59 PM8/5/06
to

"Peter Williams" <pewtas...@boy.bigpond.net.au> wrote:

>Dennis Passmore has given me and answer to this.

If you want to get rid of these warnings in general and not just
in a specific unit then you can go to the Main Menu ->
Project -> Options -> Compiler Messages tab.
Scroll down to the bottom of the Warnings list and uncheck them.

/C-H

Dennis Passmore

unread,
Aug 6, 2006, 7:01:20 AM8/6/06
to
I have one include file that I usually include in all projects as follows

----- WarningsOff.inc ----------------
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF CompilerVersion >= 14}
{$WARN SYMBOL_PLATFORM OFF}
{$WARN SYMBOL_DEPRECATED OFF}
{$WARN SYMBOL_LIBRARY OFF}
{$WARN UNIT_DEPRECATED OFF}
{$WARN UNIT_LIBRARY OFF}
{$WARN UNIT_PLATFORM OFF}


{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}

{$IFEND}
{$ENDIF}
---------------------

and it gets ride of all unwanted warnings in the IDE or even DCC32.exe when compiling the project
from the command line.

I just add the following line to the project .dpr file and do not worry about the rest.

{$I WarningsOff.inc}

0 new messages