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

Delphi基础开发技巧(13)

来源:远方网络 | 2005-12-31 9:29:49 | (有2190人读过)

[DELPHI]列举当前系统运行进程

uses TLHelp32;

procedure TForm1.Button1Click(Sender: TObject);

var lppe: TProcessEntry32;

found : boolean;

Hand : THandle;

begin

Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

found := Process32First(Hand,lppe);

while found do

begin

ListBox1.Items.Add(StrPas(lppe.szExeFile));

found := Process32Next(Hand,lppe);

end;

end;

[DELPHI]根据BDETable1建立新表Table2

Table2:=TTable.Create(nil);

try

Table2.DatabaseName:=Table1.DatabaseName;

Table2.FieldDefs.Assign(Table1.FieldDefs);

Table2.IndexDefs.Assign(Table1.IndexDefs);

Table2.TableName:='new_table';

Table2.CreateTable();

finally

Table2.Free();

end;

[DELPHI]最菜理解DLL建立和引用

//先看DLL source(FILE-->NEW-->DLL)

library project1;

uses

SysUtils, Classes;

function addit(f:integer;s:integer):integer;export;

begin

makeasum:=f+s;

end;

exports

addit;

end.

//调用(IN ur PROJECT)

implementation

function addit(f:integer;s:integer):integer;far;external 'project1';//申明

{调用就是addit(2,4);结果显示6}

[DELPHI]动态读取程序自身大小

function GesSelfSize: integer;

var

f: file of byte;

begin

filemode := 0;

assignfile(f, application.exename);

reset(f);

Result := filesize(f);//单位是字节

closefile(f);

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]动态建立MSSQL别名

procedure TForm1.Button1Click(Sender: TObject);

var MyList: TStringList;

begin

MyList := TStringList.Create;

try

with MyList do

begin

Add('SERVER NAME=210.242.86.2');

Add('DATABASE NAME=db');

Add('USER NAME=sa');

end;

Session1.AddAlias('TESTSQL', 'MSSQL', MyList); //ミMSSQL

Session1.SaveConfigFile;

finally

MyList.Free;

Session1.Active:=True;

Database1.DatabaseName:='DB';

Database1.AliasName:='TESTSQL';

Database1.LoginPrompt:=False;

Database1.Params.Add('USER NAME=sa');

Database1.Params.Add('PASSWORD=');

Database1.Connected:=True;

end;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

Database1.Connected:=False;

Session1.DeleteAlias('TESTSQL'); 

end;

[DELPHI]播放背景音乐

uses mmsystem

//播放音乐

MCISendString('OPEN e:\1.MID TYPE SEQUENCER ALIAS NN', '', 0, 0);

MCISendString('PLAY NN FROM 0', '', 0, 0);

MCISendString('CLOSE ANIMATION', '', 0, 0);

end;

//停止播放

MCISendString('OPEN e:\1.MID TYPE SEQUENCER ALIAS NN', '', 0, 0);

MCISendString('STOP NN', '', 0, 0);

MCISendString('CLOSE ANIMATION', '', 0, 0);



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

 

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

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