Delphi实验3

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1一·实验目标1、内容:键鼠、多媒体编程及DLL创建和使用2、要求:掌握键盘鼠标编程常用事件;掌握DLL编程方法。二·实验内容实验一1、实验内容:关于鼠标拖动操作的验证性实验:教材158页例6.32、实验结果:运行代码(如图1)图12将输入文本拖至下方(如图2)图23、核心代码:procedureTForm1.Edit1MouseDown(Sender:TObject;Button:TMouseButton;Shift:TShiftState;X,Y:Integer);beginifButton=mbLeftthen(SenderAsTEdit).BeginDrag(False);end;procedureTForm1.Memo1DragDrop(Sender,Source:TObject;X,Y:Integer);beginif(SenderIsTmemo)and(SourceIsTedit)then(SenderAsTmemo).Lines.Add((SourceAsTEdit).Text);end;3procedureTForm1.Memo1DragOver(Sender,Source:TObject;X,Y:Integer;State:TDragState;varAccept:Boolean);beginbeginifSourceIsTeditthenAccept:=True;end;end;实验二1、实验内容:4完成下面截图关于图形组件以及画笔画刷使用的程序,可参考教材176页例7.32、运行结果5如图3图33、核心代码procedureTForm1.FormCreate(Sender:TObject);beginpen:=1;penbrush:=true;SetLength(p,1);end;procedureTForm1.N1Click(Sender:TObject);beginifopendialog1.Executethenbegin6end;end;procedureTForm1.N2Click(Sender:TObject);beginifsavedialog1.Executethenbeginend;end;procedureTForm1.PaintBox1MouseDown(Sender:TObject;Button:TMouseButton;Shift:TShiftState;X,Y:Integer);beginfirstp.X:=X;firstp.Y:=y;p:=nil;SetLength(p,1);p[0].X:=X;p[0].Y:=Y;SetLength(p,length(p)+1);end;procedureTForm1.PaintBox1MouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);beginp[high(p)].X:=X;p[high(p)].Y:=Y;SetLength(p,length(p)+1);end;7procedureTForm1.PaintBox1MouseUp(Sender:TObject;Button:TMouseButton;Shift:TShiftState;X,Y:Integer);beginif(pen=1)then//画笔beginpenbrush:=true;p[high(p)].X:=X;p[high(p)].Y:=Y;PaintBox1.Canvas.Polyline(p);end;if(pen=2)then//直线beginPaintBox1.Canvas.MoveTo(firstp.X,firstp.Y);PaintBox1.Canvas.LineTo(X,Y);end;if(pen=3)then//矩形beginPaintBox1.Canvas.rectangle(firstp.X,firstp.Y,X,Y);end;if(pen=4)then//圆形beginPaintBox1.Canvas.ellipse(firstp.X,firstp.Y,X,Y);end;if(pen=5)then//圆角矩形beginPaintBox1.Canvas.roundrect(firstp.X,firstp.Y,X,Y,10,10);end;end;procedureTForm1.Button10Click(Sender:TObject);//修改颜色begin8ifColorDialog1.ExecutethenbeginPaintBox1.Canvas.Pen.Color:=ColorDialog1.ColorendelsebeginPaintBox1.Canvas.Pen.Color:=clBlack;end;end;procedureTForm1.Button11Click(Sender:TObject);beginPaintBox1.Canvas.Brush.Style:=bsSolid;end;procedureTForm1.Button13Click(Sender:TObject);beginPaintBox1.Canvas.Brush.Style:=bsBDiagonal;end;procedureTForm1.Button14Click(Sender:TObject);beginPaintBox1.Canvas.Brush.Style:=bsFDiagonal;end;procedureTForm1.Button15Click(Sender:TObject);beginPaintBox1.Canvas.Brush.Style:=bsCross;end;procedureTForm1.Button16Click(Sender:TObject);beginPaintBox1.Canvas.Brush.Style:=bsDiagCross;9end;procedureTForm1.Button19Click(Sender:TObject);//修改填充色beginifColorDialog1.ExecutethenbeginPaintBox1.Canvas.Brush.Color:=ColorDialog1.ColorendelsebeginPaintBox1.Canvas.Brush.Color:=clBlack;end;end;procedureTForm1.Button1Click(Sender:TObject);//linebeginpen:=2;//showmessage(inttostr(pen));end;procedureTForm1.Button2Click(Sender:TObject);//矩形beginpen:=3;end;procedureTForm1.Button3Click(Sender:TObject);//圆形beginpen:=4;end;procedureTForm1.Button4Click(Sender:TObject);//圆角矩形beginpen:=5;10end;procedureTForm1.Button5Click(Sender:TObject);//画笔beginpen:=1;end;procedureTForm1.Button6Click(Sender:TObject);beginpenbrush:=false;pen:=6;PaintBox1.Canvas.Brush.Style:=bsSolid;PaintBox1.Canvas.Brush.Color:=clBlack;end;procedureTForm1.Button7Click(Sender:TObject);//实线beginPaintBox1.Canvas.Pen.Style:=psSolid;end;procedureTForm1.Button8Click(Sender:TObject);//虚线beginPaintBox1.Canvas.Pen.Style:=psDash;end;procedureTForm1.Button9Click(Sender:TObject);//点虚线beginPaintBox1.Canvas.Pen.Style:=psDashDot;end;procedureTForm1.Edit1Change(Sender:TObject);//修改粗细beginPaintBox1.Canvas.Pen.Width:=strtoint(Edit1.text);11end;实验三1、实验内容:媒体播放器组件的使用:教材189页例7.102、实验结果:运行代码(如图4)图412点击打开按钮,选择示例视频(如图5)图5点击播放(如图6)图63、核心代码procedureTForm1.Button1Click(Sender:TObject);begin13opendialog1.DefaultExt:='AVT';opendialog1.FileName:='*.wmv';ifopendialog1.Executethenbeginmediaplayer1.FileName:=opendialog1.FileName;mediaplayer1.Open;end;end;procedureTForm1.Button2Click(Sender:TObject);beginmediaplayer1.Next;end;procedureTForm1.Button3Click(Sender:TObject);beginmediaplayer1.Back;end;procedureTForm1.Button4Click(Sender:TObject);beginmediaplayer1.Open;mediaplayer1.Play;end;procedureTForm1.Button5Click(Sender:TObject);beginifbutton5.Caption='暂停'thenbutton5.Caption:='恢复'elsebutton5.Caption:='暂停';mediaplayer1.Pause;end;14实验四1、实验内容:DLL文件的创建:教材204页课后题8-52、核心代码libraryProject1;usesSysUtils,Classes;{$R*.res}vari:integer;flag:boolean;functionsushu(a:integer):boolean;stdcall;beginflag:=true;fori:=2toadobeginif(amodi=0)and(ia)thenbeginflag:=false;break;end;end;result:=flag;end;exportssushu;beginend.实验五1、实验内容15DLL文件的静态调用和动态调用:教材204页课后题8-52、实验结果运行代码(如图7)图7输入数字,例3,点击静态(如图8),点击动态(如图9)图8图916输入数字,例4,点击静态(如图10),点击动态(如图11)图10图113、核心代码:implementation{$R*.dfm}functionsushu(a:integer):Boolean;stdcall;external'Project1.dll';procedureTForm1.Button1Click(Sender:TObject);beginifsushu(strtoint(edit1.Text))thenedit1.Text:='该数是素数!'elseedit1.Text:='该数不是素数!';end;TypeTsushu=function(a:integer):Boolean;stdcall;procedureTForm1.Button2Click(Sender:TObject);17v

1 / 17
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功