📄 auto.txt
字号:
用Delphi的人对TMediaPlayer组件比较熟悉,它是一个相当出色的多用途的多媒体组件,但是美中不足的是:如果CDROM光驱的仓门打开就不能自动关闭。而且不幸的是,TMediaPlayer的方法和属性中没有解决这个问题的办法,所以我们不得不求助于Windows API,具体一些就是使用MMSystem.pas文件,另外一件需要注意的事是:我们可以单独调用Windows API函数,但是TMediaPlayer做了一些内部处理,所以我们就不必担心我们是否使用了组件。所以本例中使用了TMediaPlayer。
第一步 新建一个工程,然后把一个TMediaPlayer 和 TButton拖到它上面。
第二步 在窗体的uses语句中添加一个MMSystem声明。
第三步 设置TMediaPlayer的AutoOpen属性为真,设置DeviceType属性为dtCDAudio,除此之外我们还可以关闭EnabledButtons属性的btEject选项,因为我们将使用代码来完成这个功能。
第四步 在某些应用程序中,我还要使用到数据CD,所以我也要设置Visible属性为假,让我的按钮做开关仓门的动作。
第五步 就是在按钮的onclick 事件中添加下面的代码:
procedure TForm1.Button2Click(Sender: TObject);
begin
with MediaPlayer1 do
if (MediaPlayer1.Mode = mpOpen) then
mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0)
else
mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
end;
注意,我们使用了mciSendCommand函数,在Windows中,每个东西都是被消息控制,在设备控制方面,mciSnedCommand与windows的WndProc非常相似,都象是一个消息分发器,提供给设备了消息类型、消息标志、消息参数以及你所使用的方法。如果您想了解更详细的信息的话,请您参阅帮助文件。
AND Stepping, 0FH //取得CPU STEPPING数送入到变量Stepping中
AND AL, 0F0H
SHR AL, 4
MOV Model, AL //取得CPU MODEL数送入到变量Model中
SHR AX, 8
AND AL, 0FH
MOV Family, AL //取得CPU FAMILYG数送入到变量Family中
POP EAX
end;
//RSA的加密和解密函数,等价于(m^e) mod n(即m的e次幂对n求余)
function Encrypt_Decrypt(m: Int64; e: Int64=$2C86F9; n: Int64=$69AAA0E3): Int64;
var
a, b, c: Int64;
begin
a:=m;
b:=e;
c:=1;
while b<>0 do
if (b mod 2)=0
then begin
b:=b div 2;
a:=(a * a) mod n;
end
else begin
b:=b - 1;
c:=(a * c) mod n;
end;
Result:=c;
end;
procedure TForm1.GetKeySpeedButtonClick(Sender: TObject);
var
ID, UserName, CpuVer: String;
s: Array [1..4] of Cardinal;
temp, Num1, Num2: Cardinal;
Code1, Code2: Int64;
i, ascii: Byte;
Reg: TRegistry;
begin
if (Edit1.Text='') and (CheckBox1.Checked=False)
then Application.MessageBox('请输入注册申请码!', '警告', MB_OK);
if (Edit1.Text='') and (CheckBox1.Checked=True)
then Application.MessageBox('请输入注册者姓名!', '警告', MB_OK);
if (CheckBox1.Checked=true) and (Edit1.Text<>'')
then begin
UserName:=Edit1.Text; //从Edit1.Text中取得用户名
GetCpuID; //调用过程GetCpuID
CpuVer:='Level '+IntToStr(Family)+' Rev. '+IntToStr(Model)+'.'+IntToStr(Stepping);
temp:=1;
i:=1;
while UserName[i]<>#0 do begin
ascii:=ord(UserName[i]); //函数ord()的作用为取得字符的ASCII码
temp:=(temp*ascii+$D0878) mod $F4240;
inc(i);
end;
i:=1;
while CpuVer[i]<>#0 do begin
ascii:=ord(CpuVer[i]);
temp:=(temp*ascii+$2597D) mod $F4240;
inc(i);
end;
ID:=IntToStr(temp);
end;
if (CheckBox1.Checked=false) and (Edit1.Text<>'')
then ID:=Edit1.Text;
ID:=ID+'1234567';
SetLength(ID, 8); //把字符串ID长度变为8个,并把后面的字符截掉
//下面四行语句是把字符串'You are big pig.'的内存数据送到变量s中
s[1]:=$20756f59;
s[2]:=$20657261;
s[3]:=$20676962;
s[4]:=$2e676970;
Num1:=0;
for i:=4 downto 2 do
Num1:=(Num1+ord(ID[i])) shl 8;
Num1:=Num1+ord(ID[1]);
Num2:=0;
for i:=8 downto 6 do
Num2:=(Num2+ord(ID[i])) shl 8;
Num2:=Num2+ord(ID[5]);
temp:=0;
for i:=1 to 32 do begin
temp:=temp+$9E3779B9;
Num1:=Num1+(Num2 shl 4)+(s[1] xor Num2)+((Num2 shr 5) xor temp)+s[2];
Num2:=Num2+(Num1 shl 4)+(s[3] xor Num1)+((Num1 shr 5) xor temp)+s[4];
end;
Code1:=(Num1 mod $40000000) + 2;
Code2:=($93E0014 shl 2)+ Num1 div $40000000 + 2;
Code1:=Encrypt_Decrypt(Code1);
code2:=Encrypt_Decrypt(Code2);
if (CheckBox1.Checked=False) and (Edit1.Text<>'')
then begin
Edit2.Text:=IntToHex(Code1, 8);
Edit3.Text:=IntToHex(Code2, 8);
end;
if (CheckBox1.Checked=True) and (Edit1.Text<>'')
then begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software\Wom', True)
then begin
Reg.DeleteValue('Masters');
Reg.WriteString('Register', UserName);
Reg.WriteString('Register_1', IntToHex(Code1, 8));
Reg.WriteString('Register_2', IntToHex(Code2, 8));
end;
Reg.Free;
Application.MessageBox('自动注册完成!', '信息', MB_OK);
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked=true
then begin
GetKeySpeedButton.Caption:='自动注册';
Label1.Caption:='注册者姓名';
Edit1.MaxLength:=0;
Label2.Visible:=false;
Label3.Visible:=false;
Edit2.Visible:=false;
Edit3.Visible:=false;
end
else begin
GetKeySpeedButton.Caption:='取得注册码';
Label1.Caption:='注册申请码';
Edit1.MaxLength:=8;
Label2.Visible:=true;
Label3.Visible:=true;
Edit2.Visible:=true;
Edit3.Visible:=true;
end;
end;
end.
propertyDataSource:TDataSourcereadGetDataSource
writeSetDataSource;//为控件增加DataSource属性,使它能与DataSource构件连接propertyDataField:StringreadGetDataField
writeSetDataField;
end;//为控件增加DataField属性,使它指向代表某一字段的TField对象procedureRegister;//注册构件implementation
procedureTDBDateTime.CMExit;
begin
try
FDataLink.UpdateRecord;
//控件失去焦点时更新DataSet,这将触发OnUpdateData事件except
Setfocus;
raise;
end;
DoExit;
end;
constructorTDBDateTime.Create(Aowner:Tcomponent);
begin
inheritedCreate(Aowner);
//创建DataLink对象,挂接OnDataChange、OnUpdateData事件处理句柄FDataLink:=TFieldDataLInk.Create;
FDataLink.OnDataChange:=DataChange;
FDataLink.OnUpdateData:=Updatedata;
end;
DestructorTDBDateTime.Destroy;
begin
FDataLink.OnDataChange:=nil;
FDataLink.OnUpdateData:=nil;
FDataLink.Free;
inheritedDestroy;
end;
functionTDBDateTime.GetdataSource:TdataSource;
begin
result:=FDataLink.DataSource;
end;
ProcedureTDBDateTime.SetDataSource(Value:TDataSource);
begin
FDataLink.DataSource:=Value;
end;
functionTDBDateTime.GetDatafield:String;
begin
result:=FDataLink.FieldName;
end;
procedureTDBDateTime.SetDataField(value:String);
begin
FdataLink.FieldName:=value;
end;
procedureTDBDateTime.DataChange(Sender:Tobject);
begin
DateTime:=now;
//若控件连了活动的DataSet则数据集变动时控件显示当前记录的相应字段值ifFDataLink.Field nilthen
ifFDataLink.Field.Text ''then
DateTime:=FDatalink.Field.AsDateTime;
end;
ProcedureTDBDateTime.UpdateData(sender:Tobject);
begin
FDatalink.Field.AsDateTime:=DateTime;
//用控件中的日期、时间更新相应字段end;
procedureTDBDateTime.Change;
begin
//当用户改变了控件中的内容时将DataSet置为编辑状态FDataLink.Modified;
ifnotFDataLink.Editingthen
FdataLink.Edit;
inheritedChange;
end;
procedureTDBDateTime.Notification(AComponent:
TComponent;Operation:TOperation);
begin
inheritedNotification(Acomponent
Operation);
//当与控件相连的TdataSource
被删除时将控件的DataSource属性置为空if(Operation=opRemove)and(FDataLink nil)
and(AComponent=Datasource)then
DataSource:=nil;
end;
procedureRegister;
begin
RegisterComponents('DataControls'
[TDBDateTime]);//控件注册后安装于DataControls页end;
end.
本控件安装后能以下拉日历和递增递减方式改变数据库的日期时间型字段,并能以长、短两种格式显示日期,方便实用。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -