⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 取磁盘空间及驱动器类型.rar
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,disk, FileCtrl,IniFiles,Unit2;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Button1: TButton;
    Memo1: TMemo;
    DriveComboBox1: TDriveComboBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Button3: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
function Username:string;//取得当前用户名
function Computername:string;//取得计算机名

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
var
  TotalBytes : double;
  TotalFree,x : double;
  i:double;
  drv:string;
begin
  drv:='c:\';
  GetDiskSizeAvail(pchar(drv),TotalBytes,TotalFree);
  x:= TotalBytes/1024;
  x:= x/1024;
  x:= x/1024;
  i:= int(x*100);
  i:=i /100;
  label1.Caption:= '驱动器'+drv+'总共容量: ' + FloatToStr(i)+'G字节';
  x:= TotalFree/1024;
  x:= x/1024;
  x:= x/1024;
  i:= int(x*100);
  i:=i /100;
  label2.Caption:=  '驱动器'+drv+'可用容量: ' + FloatToStr(i)+'G字节';
end;




procedure TForm1.Button1Click(Sender: TObject);
var
  x,y:integer;
  driver:pchar;
  dtype:string;
  TotalBytes : double;
  TotalFree,i : double;
  filename:string;
  myinifile:Tinifile;
begin
  filename:=ExtractFilePath(paramstr(0))+'myini.ini';//打开ini文件
  myinifile:=TInifile.Create(filename);//创建ini文件对象
{
定义
在Interface的Uses节增加IniFiles;
在Var变量定义部分增加一行:myinifile:Tinifile;

打开INI文件
myinifile:=Tinifile.create('program.ini');
上面这一行语句将会为变量myinifile与具体的文件 program.ini建立联系,然后,就可以通过变量
myinifile,来读写program.ini文件中的关键字的值了。
值得注意的是,如果括号中的文件名没有指明路径的话,那么这个Program.ini文件会存储在Windows目录
中,
把Program.ini文件存储在应用程序当前目录中的方法是:为其指定完整的路径及文件名。
下面的两条语句可以完成这个功能:
Filename:=ExtractFilePath(Paramstr(0))+'program.ini';
myinifile:=Tinifile.Create(filename);

vs:=myinifile.Readstring('小节名','关键字',缺省值); 读取string类型
vi:=myinifile.Readinteger('小节名','关键字',缺省值); 读取integer类型
vb:=myinifile.Readbool('小节名','关键字',缺省值); 读取boolean类型
其中缺省值为该INI文件不存在该关键字时返回的缺省值。

myinifile.writestring('小节名','关键字',变量或字符串值); 写入string类型
myinifile.writeinteger('小节名','关键字',变量或整型数值); 写入integer类型
myinifile.writebool('小节名','关键字',变量或True或False); 写入boolean类型
当这个INI文件不存在时,上面的语句还会自动创建该INI文件。

myinifile.DeleteKey('小节名','关键字'); 删除关键字

小节操作
myinifile.EraseSection('小节名');删除一个小节
myinifile.readsection('小节名',TStrings变量);可将指定小节中的所有关键字名读取至
一个字符串列表变量中;
myinifile.readsections(TStrings变量);可将INI文件中所有小节名读取至
一个字符串列表变量中去。
myinifile.readsectionvalues('小节名',TStrings变量);可将INI文件中指定小节的
所有行(包括关键字、=、值)读取至一个字符串列表变量中去。

myinifile.destory; 释放myinifile

}
  myinifile.writestring('名称','服务器名',Computername);//取得计算机名
  myinifile.writestring('名称','用户名称',Username);//取得用户名称
  memo1.Lines.append('服务器名='+myinifile.ReadString('名称','服务器名',' '));
  memo1.Lines.append('用户名称='+myinifile.ReadString('名称','用户名称',' '));
  y:=DriveComboBox1.Items.Count-1;
  for x :=0  to y do
  begin
    driver:=pchar(copy( DriveComboBox1.Items[x],1,2)+'\');
    dtype:=GetDiskType(driver);
    myinifile.writestring('驱动器类型',driver,dtype);
    if dtype='固定驱动器' then
      begin
        GetDiskSizeAvail(driver,TotalBytes,TotalFree);
        i:= int(TotalBytes/1024/1024/1024*100);
        i:=i /100;
        memo1.Lines.append('驱动器'+driver+'总共容量: ' + FloatToStr(i)+'G字节');
        myinifile.writestring('总共容量',driver,FloatToStr(i));
        i:= int(TotalFree/1024/1024/1024*100);
        i:=i /100;
        memo1.Lines.append('驱动器'+driver+'可用容量: ' + FloatToStr(i)+'G字节');
        myinifile.writestring('可用容量',driver,FloatToStr(i));
      end;
  end;
  myinifile.Destroy;//释放ini文件对象

end;

procedure TForm1.Button3Click(Sender: TObject);//身份证15位升18位
var
  id:string;
begin
  id:=edit1.text;
  edit2.Text:=f(id);
end;

function Username:string;//取得当前用户名
var
  Username : pChar;
  nSize : DWORD;
  name:string;
begin
  Username:=StrAlloc(30);
  nSize:=30;
  GetUserName(Username,nSize);
  name:=username;
  Result:=name;
  StrDispose(Username);
end;

function Computername:string;//取得计算机名
var
  Username : pChar;
  nSize : DWORD;
  name:string;
begin
  Username:=StrAlloc(30);
  nSize:=30;
  GetComputerName(Username,nSize);
  name:=username;
  Result:=name;
  StrDispose(Username);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -