昨天我看了关于提取磁盘序列号的文章,可是我自己怎么使用时错误?
unit diver;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); {}
var
SerialNum : pdword;
a, b : Dword;
Buffer: array [0..255] of char; //缓冲区
begin
if GetVolumeInformation('', Buffer, SizeOf(Buffer), SerialNum, b, a,
nil, 0)then
Edit1.Text:= IntToStr(SerialNum^)else
Edit1.Text:='提取错误¡'
end;procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;end.
出现错误提示如下:
[Warning] diver.pas(40): Variable 'SerialNum' might not have been initialized
解决马上给分!!!谢谢,谢谢,毕业设计明天要交的!
unit diver;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); {}
var
SerialNum : pdword;
a, b : Dword;
Buffer: array [0..255] of char; //缓冲区
begin
if GetVolumeInformation('', Buffer, SizeOf(Buffer), SerialNum, b, a,
nil, 0)then
Edit1.Text:= IntToStr(SerialNum^)else
Edit1.Text:='提取错误¡'
end;procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;end.
出现错误提示如下:
[Warning] diver.pas(40): Variable 'SerialNum' might not have been initialized
解决马上给分!!!谢谢,谢谢,毕业设计明天要交的!
var
SerialNum : dword;
a, b : Dword;
Buffer: array [0..255] of char; //缓冲区
begin
if GetVolumeInformation('', Buffer, SizeOf(Buffer), @SerialNum, b, a,
nil, 0) then
Edit1.Text:= IntToStr(SerialNum) else
Edit1.Text:='提取错误¡'
end;
var
SectorsPerCluster, // holds the sectors per cluster
BytesPerSector, // holds the bytes per sector
FreeClusters, // holds the number of free clusters
Clusters: DWORD; // holds the total number of disk clusters
begin
{retrieve the disk space information}
if GetDiskFreeSpace('C:\',SectorsPerCluster,BytesPerSector, FreeClusters,Clusters) then
begin
{display the disk space information}
Panel2.Caption := IntToStr(SectorsPerCluster);
Panel3.Caption := IntToStr(BytesPerSector);
Panel4.Caption := IntToStr(FreeClusters);
Panel5.Caption := IntToStr(Clusters);
Panel6.Caption := IntToStr(FreeClusters*BytesPerSector*SectorsPerCluster);
Panel7.Caption := IntToStr(Clusters*BytesPerSector*SectorsPerCluster); end;
end;
谢谢你,不过那好像不是磁盘序列号啊 !麻烦给解释下!小弟初学!
var
mp : TMediaPlayer;
msp : TMCI_INFO_PARMS;
MediaString : array[0..255] of char;
ret : longint;
begin
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := 'D:';
mp.Open;
Application.ProcessMessages;
FillChar(MediaString, sizeof(MediaString), #0);
FillChar(msp, sizeof(msp), #0);
msp.lpstrReturn := @MediaString;
msp.dwRetSize := 255;
ret := mciSendCommand(Mp.DeviceId,
MCI_INFO,
MCI_INFO_MEDIA_IDENTITY,
longint(@msp));
if Ret <> 0 then begin
MciGetErrorString(ret, @MediaString, sizeof(MediaString));
Memo1.Lines.Add(StrPas(MediaString));
end else
Memo1.Lines.Add(StrPas(MediaString));
mp.Close;
Application.ProcessMessages;
mp.free;
end;end.
不能用GetVolumeInformation