电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> .NET
在DELPHI中获得磁盘容量-.NET教程,评论及其它
作者:网友供稿 点击:153
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 

使用如下api函数

bool getdiskfreespace(

    lpctstr lprootpathname, // address of root path
    lpdword lpsectorspercluster, // address of sectors per cluster
    lpdword lpbytespersector, // address of bytes per sector
    lpdword lpnumberoffreeclusters, // address of number of free clusters 
    lpdword lptotalnumberofclusters  // address of total number of clusters 
   ); 
 

parameters

lprootpathname

points to a null-terminated string that specifies the root directory of the disk to return information about. if lprootpathname
 is null, the function uses the root of the current directory.

lpsectorspercluster

points to a variable for the number of sectors per cluster.

lpbytespersector

points to a variable for the number of bytes per sector.

lpnumberoffreeclusters

points to a variable for the total number of free clusters on the disk.

lptotalnumberofclusters

points to a variable for the total number of clusters on the disk.

 

return values

if the function succeeds, the return value is nonzero.
if the function fails, the return value is zero. to get extended error information, call getlasterror.

 例子:

procedure tform1.button1click(sender: tobject);
var drivestring:string;
    sec1, byt1, cl1, cl2: longword;
    disk_freespace : real;

begin
  getdiskfreespace(d:\, sec1, byt1, cl1, cl2);
  disk_freespace := (cl1 / (1024*1024*1024))*sec1*byt1;
  showmessage(format(该驱动器容量是%0.3fg,[disk_freespace]));
end;

   上面的程序是将数据从字节单位转换为g的,之所以这样做,是为了避免当磁盘容量大于delphi基本数据类型所能存储的最大值,避免溢出。如果想获得以字节为单位的,那么将遇到大数相乘的问题。   

   下面提供一个大数相乘的算法,他接收两个字符串,输出这个两个字符串的乘积(当然字符串里都是数字)

  function tform1.xaddy(x, y: string): string;
var
   a,b,c:array[1..1000] of integer;
   i,j,k,l,m,code:integer;
   s,p,r:string;
begin
   s := x; //两个要相乘的字符串
   p := y;
   l:=length(s);
   for i:=l downto 1 do
    val(s[i],a[l-i+1],code);
   m:=length(p);
   for i:=m downto 1 do
    val(p[i],b[m-i+1],code);
   for j:=1 to m do
     for i:=1 to l do
     begin
       if c[i+j-1]+a[i]*b[j]<=9 then begin
        c[j+i-1]:=c[i+j-1]+a[i]*b[j];
        k:=i+j-1;
       end else begin
         c[j+i-1]:=c[i+j-1]+(a[i]*b[j]) mod 10;
         c[j+i]:=c[j+i]+ c[j+i-1] div 10+ (a[i]*b[j]) div 10;
         c[i+j-1]:=c[i+j-1] mod 10;
         k:=i+j;
       end;
     end;
     r := ;
     for i:=k downto 1 do
       r := r+inttostr(c[i]);
   result := r;

end;

     下面我们就可以通过使用大数相乘的算法的得到磁盘的容量(用字节表示)

procedure tform1.button2click(sender: tobject);
var
    sec1, byt1, cl1, cl2: longword;
    disk_freespace : string;

begin
  getdiskfreespace(d:\, sec1, byt1, cl1, cl2);
  disk_freespace := xaddy(inttostr(cl1),inttostr(sec1*byt1));
  showmessage(format(该驱动器容量是%s字节,[disk_freespace]));
end;

 


 

程序完整的代码如下:

unit unit1;

interface

uses
  windows, messages, sysutils, variants, classes, graphics, controls, forms,
  dialogs, stdctrls;

type
  tform1 = class(tform)
    button1: tbutton;
    label1: tlabel;
    label2: tlabel;
    button2: tbutton;
    label3: tlabel;
    procedure button1click(sender: tobject);
    procedure button2click(sender: tobject);
  private
    { private declarations }
  public
    function xaddy(x : string;y:string) : string;
  end;

var
  form1: tform1;

implementation

{$r *.dfm}
procedure tform1.button1click(sender: tobject);
var drivestring:string;
    sec1, byt1, cl1, cl2: longword;
    disk_freespace : real;

begin
  getdiskfreespace(d:\, sec1, byt1, cl1, cl2);
  disk_freespace := (cl1 / (1024*1024*1024))*sec1*byt1;
  showmessage(format(该驱动器容量是%0.3fg,[disk_freespace]));
end;

function tform1.xaddy(x, y: string): string;
var
   a,b,c:array[1..1000] of integer;
   i,j,k,l,m,code:integer;
   s,p,r:string;
begin
   s := x; //两个要相乘的字符串
   p := y;
   l:=length(s);
   for i:=l downto 1 do
    val(s[i],a[l-i+1],code);
   m:=length(p);
   for i:=m downto 1 do
    val(p[i],b[m-i+1],code);
   for j:=1 to m do
     for i:=1 to l do
     begin
       if c[i+j-1]+a[i]*b[j]<=9 then begin
        c[j+i-1]:=c[i+j-1]+a[i]*b[j];
        k:=i+j-1;
       end else begin
         c[j+i-1]:=c[i+j-1]+(a[i]*b[j]) mod 10;
         c[j+i]:=c[j+i]+ c[j+i-1] div 10+ (a[i]*b[j]) div 10;
         c[i+j-1]:=c[i+j-1] mod 10;
         k:=i+j;
       end;
     end;
     r := ;
     for i:=k downto 1 do
       r := r+inttostr(c[i]);
   result := r;

end;

procedure tform1.button2click(sender: tobject);
var
    sec1, byt1, cl1, cl2: longword;
    disk_freespace : string;

begin
  getdiskfreespace(d:\, sec1, byt1, cl1, cl2);
  disk_freespace := xaddy(inttostr(cl1),inttostr(sec1*byt1));
  showmessage(format(该驱动器容量是%s字节,[disk_freespace]));
end;

end.

 


文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·经典收藏之 - C++内存管理详解-.NET教程,C#语言
·Master Page 初探-.NET教程,评论及其它
·GDI+编程10个基本技巧-.NET教程,评论及其它
·VB.NET中让Textbox只能输入数字(二)-.NET教程,VB.Net语言
·stl应用小问题-.NET教程,评论及其它
·WIN32中颜色值(COLORREF)与.NET中颜色值(Color)的转换-ASP教程,系统相关
·打造自己的专业图像工具-Visual C++ 2005图像编程系列【三】-.NET教程,C#语言
·.Net中常见问题及解决方法归类-.NET教程,.NET Framework
·Lex和Yacc从入门到精通(3)--一个极其简单的lex和yacc程序-.NET教程,评论及其它
·VB下几个非常有用的函数-.NET教程,VB.Net语言

最新文章
·VC#初学入门:第一个Windows程序
·ASP.NET 2.0-选用DataSet或DataReader
·用.net 处理xmlHttp发送异步请求
·asp.net创建文件夹的IO类的问题
·asp.net 2.0 中加密web.config 文件中的配置节
·关于ASP.NET调用JavaScript的实现
·如何实现ASP.NET网站个性化
·Acegi安全系统的配置-.NET教程,评论及其它
·Spring安全系统:Acegi Security Acegi简介-.NET教程,评论及其它
·Biztalk 开发之 架构和实例的验证-.NET教程,评论及其它


 
 


版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号