电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> delphi技术>>Delphi基础开发技巧(4):

Delphi基础开发技巧(4)

来源:远方网络 | 2005-12-31 9:27:02 | (有1818人读过)

[DELPHI]简单地播放和暂停WAV文件

uses mmsystem;

function PlayWav(const FileName: string): Boolean;

begin

Result := PlaySound(PChar(FileName), 0, SND_ASYNC);

end;

procedure StopWav;

var

buffer: array[0..2] of char;

begin

buffer[0] := #0;

PlaySound(Buffer, 0, SND_PURGE);

end;

[DELPHI]取机器BIOS信息

with Memo1.Lines do

begin

Add('MainBoardBiosName:'+^I+string(Pchar(Ptr($FE061))));

Add('MainBoardBiosCopyRight:'+^I+string(Pchar(Ptr($FE091))));

Add('MainBoardBiosDate:'+^I+string(Pchar(Ptr($FFFF5))));

Add('MainBoardBiosSerialNo:'+^I+string(Pchar(Ptr($FEC71))));

end;

[DELPHI]网络下载文件

uses UrlMon;

function DownloadFile(Source, Dest: string): Boolean;

begin

try

Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;

except

Result := False;

end;

end;

if DownloadFile('http://www.borland.com/delphi6.zip, 'c:\kylix.zip') then

ShowMessage('Download succesful')

else ShowMessage('Download unsuccesful')

[DELPHI]解析服务器IP地址

uses winsock

function IPAddrToName(IPAddr : String): String;

var

SockAddrIn: TSockAddrIn;

HostEnt: PHostEnt;

WSAData: TWSAData;

begin

WSAStartup($101, WSAData);

SockAddrIn.sin_addr.s_addr:= inet_addr(PChar(IPAddr));

HostEnt:= gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);

if HostEnt<>nil then result:=StrPas(Hostent^.h_name) else result:='';

end;

[DELPHI]取得快捷方式中的连接

function ExeFromLink(const linkname: string): string;

var

FDir,

FName,

ExeName: PChar;

z: integer;

begin

ExeName:= StrAlloc(MAX_PATH);

FName:= StrAlloc(MAX_PATH);

FDir:= StrAlloc(MAX_PATH);

StrPCopy(FName, ExtractFileName(linkname));

StrPCopy(FDir, ExtractFilePath(linkname));

z:= FindExecutable(FName, FDir, ExeName);

if z > 32 then

Result:= StrPas(ExeName)

else

Result:= '';

StrDispose(FDir);

StrDispose(FName);

StrDispose(ExeName);

end;

[DELPHI]控制TCombobox的自动完成

{'Sorted' property of the TCombobox to true }

var lastKey: Word; //全局变量

//TCombobox的OnChange事件

procedure TForm1.AutoCompleteChange(Sender: TObject);

var

SearchStr: string;

retVal: integer;

begin

SearchStr := (Sender as TCombobox).Text;

if lastKey <> VK_BACK then // backspace: VK_BACK or $08

begin

retVal := (Sender as TCombobox).Perform(CB_FINDSTRING, -1, LongInt(PChar(SearchStr)));

if retVal > CB_Err then

begin

(Sender as TCombobox).ItemIndex := retVal;

(Sender as TCombobox).SelStart := Length(SearchStr);

(Sender as TCombobox).SelLength :=

(Length((Sender as TCombobox).Text) - Length(SearchStr));

end; // retVal > CB_Err

end; // lastKey <> VK_BACK

lastKey := 0; // reset lastKey

end;

//TCombobox的OnKeyDown事件

procedure TForm1.AutoCompleteKeyDown(Sender: TObject; var Key: Word;

Shift: TShiftState);

begin

lastKey := Key;

end;



delphi技术热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号