🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #139

Re: Delphi 7 Unsafe Code

#139
From: Ma�l H�rz
Date: Tue, 20 Jan 2004 22:34
50 lines
2291 bytes
These "unsafe" warnings were introduced because of Delphi .NET.
Borland wants to show which code shouldn't be used anymore if it should stay
protable. .NET still allows pointers but only in "unsafe sections".
The Windows API however requires you sometimes to use pointers, only in
combination with .NET these warnings can really be avoided, using the new
.NET-Api.
You could redeclare the WinAPI call to use var-Parameters.

Something like this (However I don't think this is really nice nor usefull):

Declaration:
========
function GetDiskFreeSpaceEx(var Directory: Char; var FreeAvailable,
    TotalSpace: TLargeInteger; var TotalFree: TLargeInteger): Bool; stdcall;

calling the function:
============
var
  a, b, c: Int64;
  s: string;
begin
  s := 'C:\';
  GetDiskFreeSpaceEx(s[1], a, b, c);
   ...
end;

Cheers, Ma�l

"Paul Kumagai" <okumaware@hotmail.com> schrieb im Newsbeitrag
news:3ffbb2a3@newsgroups.borland.com...
> How do you get around the compiler warnings about unsafe type and unsafe
> code.
>
> I know that I can just turn off the warnings, but is there another way to
> make the the following call?
>
> GetDiskFreeSpaceEx(PChar(DriveLetter),
> FreeBytesAvaibleToCaller,TotalNumberOfBytes, @TotalNumberOfFreeBytes);
>
> This line of code get the following warnings
>
> unsafe type 'PChar'
>
> unsafe code '@ operator'
>
> TIA
>
> Paul Kumagai
>
>
Technical Details
Message-ID: <400dacd7@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3ffbb2a3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f94dd,fa678c05e97c10fb
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2004-01-20 14:40:18 PST
From: "Ma�l H�rz" <maelh@web.de>
Newsgroups: borland.public.delphi.nativeapi
References: <3ffbb2a3@newsgroups.borland.com>
Subject: Re: Delphi 7 Unsafe Code
Date: Tue, 20 Jan 2004 23:34:51 +0100
Lines: 52
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 212.144.210.181
Message-ID: <400dacd7@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1074638039 212.144.210.181 (20 Jan 2004 14:33:59 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail