function TForm1.GetDiskVolumeLable(DiskVolume:char):string;
var
VolumeLabel, FileSystem: Array[0..$FF] of Char;
SerialNumber, DW, SysFlags: DWord;
function DecToHex(aValue: LongInt): String; //可以这样定义函数吗?
var
w: Array[1..2] of Word absolute aValue;
function HexByte(b: Byte): String;
const
Hex: Array[$0..$F] of Char = '0123456789ABCDEF';
begin
HexByte := Hex[b shr 4] + Hex[b and $F];
end;
function HexWord(w: Word): String;
begin
HexWord := HexByte(Hi((w-3)*2)) + HexByte(Lo((w+3)*2));
end;
begin
Result := HexWord(w[1]) + HexWord(w[2]);
end;
begin
Result := '';
DiskVolume := UpCase(DiskVolume);
if (DiskVolume >= 'A') and (DiskVolume <= 'Z') then
begin
GetVolumeInformation(PChar(DiskVolume + ':\'), VolumeLabel, SizeOf(VolumeLabel),
@SerialNumber, DW, SysFlags,
FileSystem, SizeOf(FileSystem));
Result := DecToHex(SerialNumber);
end;
end;
var
VolumeLabel, FileSystem: Array[0..$FF] of Char;
SerialNumber, DW, SysFlags: DWord;
function DecToHex(aValue: LongInt): String; //可以这样定义函数吗?
var
w: Array[1..2] of Word absolute aValue;
function HexByte(b: Byte): String;
const
Hex: Array[$0..$F] of Char = '0123456789ABCDEF';
begin
HexByte := Hex[b shr 4] + Hex[b and $F];
end;
function HexWord(w: Word): String;
begin
HexWord := HexByte(Hi((w-3)*2)) + HexByte(Lo((w+3)*2));
end;
begin
Result := HexWord(w[1]) + HexWord(w[2]);
end;
begin
Result := '';
DiskVolume := UpCase(DiskVolume);
if (DiskVolume >= 'A') and (DiskVolume <= 'Z') then
begin
GetVolumeInformation(PChar(DiskVolume + ':\'), VolumeLabel, SizeOf(VolumeLabel),
@SerialNumber, DW, SysFlags,
FileSystem, SizeOf(FileSystem));
Result := DecToHex(SerialNumber);
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货