圖形顯示技巧,這是其中一段代碼
procedure TForm1.Button1Click(Sender: TObject)
var
newbmp:TBitmap
i,bmpheight,bmpwidth:integer //推拉
begin
newbmp:=TBitmap.Create
newbmp.Width:=image1.Width
newbmp.Height:=image1.Height
bmpheight:=image1.Height
bmpwidth:=image1.Width
for i:=0 to bmpheight do
begin
newbmp.Canvas.CopyRect(Rect(0,bmpheight-i,bmpwidth,bmpheight),image1.Canvas,Rect(0,0,bmpwidth,i))
form1.Canvas.Draw(120,100,newbmp)
end
newbmp.free
end
MD5變換動態(tài)鏈接庫文件調(diào)用:(delphi例子)
=========================================================================
function transfer(tran:widestring):widestring stdcall external md5.dll name transfer
//edit1為輸入字符,edit2為輸出md5摘要
procedure TForm1.Button1Click(Sender: TObject)
begin
edit2.text:=transfer(edit1.Text)
end
procedure senddata
var
i:integer commflg : Boolean
begin
commflg:=true
for i:=1 to 8 do
begin
if not fcomm comml writecommdata(sendbutter,i) then
begin
Commflg=false
break
end
end
end
(4) 接收數(shù)據(jù)
在編寫基于串口的計算機工業(yè)測控時,通常需要由下位機向PC機發(fā)送數(shù)據(jù)以使PC機了解系統(tǒng)的測試數(shù)據(jù)或下位機的運行狀態(tài),并進而控制下位機的行為。利用Spcomm串口控件接收下位機發(fā)送的數(shù)據(jù)信息的示例代碼如下:
//事件驅(qū)動方式接收數(shù)據(jù)程序
procedure TForm1.CommlReceiveData(Sender:TObject Buffer:Pointer bufferLength:Word)
var
receivedata:array of byte
begin
sleep(100) //等待100ms,保證接收到所有數(shù)據(jù)
move(buffef ,receivedata,bufferlength)
//將接收緩存區(qū)中的數(shù)據(jù)轉(zhuǎn)移到數(shù)組中
……
end
(5) 關(guān)閉串口
在系統(tǒng)開發(fā)中,應(yīng)注意在不使用串口時應(yīng)及時關(guān)閉串口,釋放系統(tǒng)資源,否則可能會影響系統(tǒng)的其它應(yīng)用。關(guān)閉串口的代碼如下:
procedure TForm1.FormClose ( Sender TObj ect:var Action:TCIoseAction )
begin
comml.StopComm
end