delphi基础开发技巧 //内联样式 div可以包含段落、标题、表格甚至其它部分 id属性 //定义见3。
Java
Asp
PHP
.Net
XML
C/C++
CGI
VB
Jsp
J2ee
J2se
J2me
EJB
Servlet
Tomcat
Resin
Struts
Weblogic
Eclipse
ANT
GUI
JMS
Web servise
IDEA
Webphere
Hibernate
Spring
Jboss
Applet
Swing
Socket
Javamail
Perl
Ajax
P2P
安全
模式
框架
测试
开源
游戏
Windows XP
Windows 2000
Windows 2003
Windows Me
Windows 9.x
Linux
UNIX
注册表
操作系统
服务器
应用服务器
◇[delphi]网络邻居复制文件
uses shellapi;
copyfile(pchar('newfile.txt'),pchar('//computername/direction/targer.txt'),false);
◇[delphi]产生鼠标拖动效果
通过mousemove事件、dragover事件、enddrag事件实现,例如在panel上的label:
var xpanel,ypanel,xlabel,ylabel:integer;
panel的mousemove事件:xpanel:=x;ypanel:=y;
panel的dragover 事件:xpanel:=x;ypanel:=y;
label的mousemove事件:xlabel:=x;ylabel:=y;
label的enddrag 事件:label.left:=xpanel-xlabel;label.top:=ypanel-ylabel;
◇[delphi]取得windows目录
uses shellapi;
var windir:array[0..255] of char;
getwindowsdirectory(windir,sizeof(windir));
或者从注册表中读取,位置:
hkey_local_machine\software\microsoft\windows\currentversion
systemroot键,取得如:c:\windows
◇[delphi]在form或其他容器上画线
var x,y:array [0..50] of integer;
canvas.pen.color:=clred;
canvas.pen.style:=psdash;
form1.canvas.moveto(trunc(x[i]),trunc(y[i]));
form1.canvas.l.neto(trunc(x[j]),trunc(y[j]));
◇[delphi]字符串列表使用
var tips:tstringlist;
tips:=tstringlist.create;
tips.loadfromfile('filename.txt');
edit1.text:=tips[0];
tips.add('last line addition string');
tips.insert(1,'insert string at no 2 line');
tips.savetofile('newfile.txt');
tips.free;
◇[delphi]简单的剪贴板操作
richedit1.selectall;
richedit1.copytoclipboard;
richedit1.cuttoclipboard;
edit1.pastefromclipboard;
◇[delphi]关于文件、目录操作
chdir('c:\abcdir');转到目录
mkdir('dirname');建立目录
rmdir('dirname');删除目录
getcurrentdir;//取当前目录名,无'\'
getdir(0,s);//取工作目录名s:='c:\abcdir';
deletfile('abc.txt');//删除文件
renamefile('old.txt','new.txt');//文件更名
extractfilename(filelistbox1.filename);//取文件名
extractfileext(filelistbox1.filename);//取文件后缀
◇[delphi]处理文件属性
attr:=filegetattr(filelistbox1.filename);
if (attr and fareadonly)=fareadonly then ... //只读
if (attr and fasysfile)=fasysfile then ... //系统
if (attr and faarchive)=faarchive then ... //存档
if (attr and fahidden)=fahidden then ... //隐藏
◇[delphi]执行程序外文件
winexec//调用可执行文件
winexec('command.com /c copy *.* c:\',sw_normal);
winexec('start abc.txt');
shellexecute或shellexecuteex//启动文件关联程序
function executefile(const filename,params,defaultdir:string;showcmd:integer):thandle;
executefile('c:\abc\a.txt','x.abc','c:\abc\',0);
executefile('http://tingweb.yeah.net','','',0);
executefile('mailto:tingweb@wx88.net','','',0);
◇[delphi]取得系统运行的进程名
var hcurrentwindow:hwnd;sztext:array[0..254] of char;
begin
hcurrentwindow:=getwindow(handle,gw_hwndfrist);
while hcurrentwindow <> 0 do
begin
if getwindowtext(hcur.netwindow,@sztext,255)>0 then listbox1.items.add(strpas(@sztext));
hcurrentwindow:=getwindow(hcurrentwindow,gw_hwndnext);
end;
end;
◇[delphi]关于汇编的嵌入
asm end;
可以任意修改eax、ecx、edx;不能修改esi、edi、esp、ebp、ebx。
◇[delphi]关于类型转换函数
floattostr//浮点转字符串
floattostrf//带格式的浮点转字符串
inttohex//整数转16进制
timetostr
datetostr
datetimetostr
fmtstr//按指定格式输出字符串
formatdatetime('yyyy-mm-dd,hh-mm-ss',date);
◇[delphi]字符串的过程和函数
insert(obj,target,pos);//字符串target插入在pos的位置。如插入结果大于target最大长度,多出字符将被截掉。如pos在255以外,会产生运行错。例如,st:='brian',则insert('ok',st,2)会使st变为'brokian'。
delete(st,pos,num);//从st串中的pos(整型)位置开始删去个数为num(整型)个字符的子字串。例如,st:='brian',则delete(st,3,2)将变为brn。
str(value,st);//将数值value(整型或实型)转换成字符串放在st中。例如,a=2.5e4时,则str(a:10,st)将使st的值为' 25000'。
val(st,var,code);//把字符串表达式st转换为对应整型或实型数值,存放在var中。st必须是一个表示数值的字符串,并符合数值常数的规则。在转换过程中,如果没有检测出错误,变量code置为0,否则置为第一个出错字符的位置。例如,st:=25.4e3,x是一个实型变量,则val(st,x,code)将使x值为25400,code值为0。
copy(st.pos.num);//返回st串中一个位置pos(整型)处开始的,含有num(整型)个字符的子串。如果pos大于st字符串的长度,那就会返回一个空串,如果pos在255以外,会引起运行错误。例如,st:='brian',则copy(st,2,2)返回'ri'。
concat(st1,st2,st3……,stn);//把所有自变量表示出的字符串按所给出的顺序连接起来,并返回连接后的值。如果结果的长度255,将产生运行错误。例如,st1:='brian',st2:=' ',st3:='wilfred',则concat(st1,st2,st3)返回'brian wilfred'。
length(st);//返回字符串表达式st的长度。例如,st:='brian',则length(st)返回值为5。
pos(obj,target);//返回字符串obj在目标字符串target的第一次出现的位置,如果target没有匹配的串,pos函数的返回值为0。例如,target:='brian wilfred',则pos('wil',target)的返回值是7,pos('hurbet',target)的返回值是0。
◇[delphi]关于处理注册表
uses registry;
var reg:tregistry;
reg:=tregistry.create;
reg.rootkey:='hkey_current_user';
reg.openkey('control panel\desktop',false);
reg.writestring('title wallpaper','0');
reg.writestring('wallpaper',filelistbox1.filename);
reg.closereg;
reg.free;
◇[delphi]关于键盘常量名
vk_back/vk_tab/vk_return/vk_shift/vk_control/vk_menu/vk_pause/vk_escape
/vk_space/vk_left/vk_right/vk_up/vk_down
f1--f12:$70(112)--$7b(123)
a-z:$41(65)--$5a(90)
0-9:$30(48)--$39(57)
◇[delphi]初步判断程序母语
delphi软件的dos提示:this program must be run under win32.
vc++软件的dos提示:this program cannot be run in dos mode.
◇[delphi]操作cookie
response.cookies("name").domain:='http://www.08.net.com';
with response.cookies.add do
begin
name:='username';
value:='username';
end
◇[delphi]增加到文档菜单连接
uses shellapi,shlobj;
shaddtorecentdocs(shard_path,pchar(filepath));//增加连接
shaddtorecentdocs(shard_path,nil);//清空
◇[杂类]备份智能abc输入法词库
windows\system\user.rem
windows\system\tmmr.rem
◇[delphi]判断鼠标按键
if getasynckeystate(vk_lbutton)<>0 then ... //左键
if getasynckeystate(vk_mbutton)<>0 then ... //中键
if getasynckeystate(vk_rbutton)<>0 then ... //右键
◇[delphi]设置窗体的最大显示
onformcreate事件
self.width:=screen.width;
self.height:=screen.height;
◇[delphi]按键接受消息
oncreate事件中处理:application.onmessage:=myonmessage;
procedure tform1.myonmessage(var msg:tmsg;var handle:boolean);
begin
if msg.message=256 then ... //any键
if msg.message=112 then ... //f1
if msg.message=113 then ... //f2
end;
◇[杂类]隐藏共享文件夹
共享效果:可访问,但不可见(在资源管理、网络邻居中)
取共享名为:direction$
访问://computer/dirction/
◇[java script]java script网页常用效果
网页60秒定时关闭
关闭窗口
关闭
定时转url
.net.com?>a, b, nil, 0) then
result := inttostr(serialnum^);
end;
◇[inte.net]css常用综合技巧
1。p:first-letter { font-size: 300%; float: left }//首字会比普通字体加大三倍。
2。css" title="contemporary">//连接一个外部样式表
3。嵌入一个样式表
4。xml:namespace prefix = p style="color />
xml:namespace prefix = span style="font-family />arial//span接受style、class和id属性
5。class属性 //定义见3。
6。
7。属性列表
字体风格:font-style: [normal italic oblique];
字体大小:font-size: [xx-small x-small small medium large x-large xx-large larger smaller <长度> <百分比>]
文本修饰:text-decoration:[ underline overline line-through blink ]
文本转换:text-transform:[none capitalize uppercase lowercase]
背景颜色:background-color:[<颜色> transparent]
背景图象:background-image:[
行高:line-height: [normal <数字> <长度> <百分比>]
边框样式:border-style: [ none dotted dashed solid double groove ridge inset outset ]
漂浮:float: [left right none]
8。长度单位
相对单位:
em (em,元素的字体的高度)
ex (x-height,字母 "x" 的高度)
px (像素,相对于屏幕的分辨率)
绝对长度:
in (英寸,1英寸=2.54厘米)
cm (厘米,1厘米=10毫米)
mm (米)
pt (点,1点=1/72英寸)
pc (帕,1帕=12点)
◇[delphi]vcl制作简要步骤
1.创建部件属性方法事件
(建立库单元,继承为新的类型,添加属性、方法、事件,注册部件,建立包文件)
2.消息处理
3.异常处理
4.部件可视
◇[delphi]动态连接库的装载
静态装载:procedure name;external 'lib.dll';
动态装载:var handle:thandle;
handle:=loadlibrary('lib.dll');
if handle<>0 then
begin
{dosomething}
freelibrary(handle);
end;
◇[delphi]指针变量和地址
var x,y:integer;p:^integer;//指向integer变量的指针
x:=10;//变量赋值
p:=@x;//变量x的地址
y:=p^;//为y赋值指针p
@@procedure//返回过程变量的内存地址
◇[delphi]判断字符是汉字的一个字符
bytetype('你好haha吗',1) = mbleadbyte//是第一个字符
bytetype('你好haha吗',2) = mbtrailbyte//是第二个字符
bytetype('你好haha吗',5) = mbsinglebyte//不是中文字符
◇[delphi]memo的定位操作
memo1.lines.delete(0)//删除第1行
memo1.selstart:=10//定位10字节处
◇[delphi]获得双字节字符内码
function getit(s: string): integer;
begin
result := byte(s[1]) * $100 + byte(s[2]);
end;
使用:getit('计')//$bcc6 即十进制 48326
◇[delphi]调用add数据存储过程
存储过程如下:
create procedure addrecord(
record1 varchar(10)
record2 varchar(20)
)
as
begin
insert into tablename (field1,field2) values(:record1,:record2)
end
执行存储过程:
execute procedure addrecord("urrecord1","urrecord2")
◇[delphi]将文件存到blob字段中
function blobcontenttostring(const filename: string):string;
begin
with tfilestream.create(filename,fmopenread) do
try
setlength(result,size);
read(pointer(result)^,size);
finally
free;
end;
end;
//保存字段
begin
if (opendialog1.execute) then
begin
sfilename:=opendialog1.filename;
adotable1.edit;
adotable1.fieldbyname('visio').asstring:=blobcontenttostring(filename);
adotable1.post;
end;
◇[delphi]把文件全部复制到剪贴板
uses shlobj,activex,clipbrd;
procedure tform1.copytoclipbrd(var filename:string);
var
fe:tformatetc;
medium: tstgmedium;
dropfiles:pdropfiles;
pfile:pchar;
begin
fe.cfformat := cf_hdrop;
fe.dwaspect := dvaspect_content;
fe.tymed := tymed_hglobal;
medium.hglobal := globalalloc(gmem_share or gmem_zeroinit, sizeof(tdropfiles)+length(filename)+1);
if medium.hglobal<>0 then begin
medium.tymed := tymed_hglobal;
dropfiles := globallock(medium.hglobal);
try
dropfiles^.pfiles := sizeof(tdropfiles);
dropfiles^.fwide := false;
longint(pfile) := longint(dropfiles)+sizeof(tdropfiles);
strpcopy(pfile,filename);
inc(pfile, length(filename)+1);
pfile^ := #0;
finally
globalunlock(medium.hglobal);
end;
clipboard.setashandle(cf_hdrop,medium.hglobal);
end;
end;
◇[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=db27%);
add('user name=sa');
end;
session1.addalias('testsql', 'mssql', mylist); //ミmssql
session1.saveconfigfile;
finally
mylist.free;
session1.active:=true;
database1.databasename:='db27%;
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]接口和类的一个范例代码
type{接口和类申明:区别在于不能在接口中申明数据成员、任何非公有的方法、公共方法不使用public关键字}
isample=interface//定义isample接口
function getstring:string;
end;
tsample=class(tinterfacedobject,isample)
public
function getstring:string;
end;
//function定义
function tsample.getstring:string;
begin
result:='what show is ';
end;
//调用类对象
var sample:tsample;
begin
sample:=tsample.create;
showmessage(sample.getstring+'class object!');
sample.free;
end;
//调用接口
var sampleinterface:isample;
sample:tsample;
begin
sample:=tsample.create;
sampleinterface:=sample;//interface的实现必须使用class
{以上两行也可表达成sampleinterface:=tsample.create;}
showmessage(sampleinterface.getstring+'interface!');
//sample.free;{和局部类不同,interface中的类自动释放}
sampleinterface:=nil;{释放接口对象}
end;
◇[delphi]任务条就看不当程序
var
extendedstyle : integer;
begin
application.initialize;
extendedstyle := getwindowlong (application.handle, gwl_exstyle);
setwindowlong(application.handle, gwl_exstyle, extendedstyle or ws_ex_toolwindow and not ws_ex_appwindow);
application.createform(tform1, form1);
application.run;
end.
◇[delphi]alt+ctrl+del看不到程序
在implementation后添加声明:
function registerserviceprocess(dwprocessid, dwtype: integer): integer; stdcall; external 'kernel32.dll';
registerserviceprocess(getcurrentprocessid, 1);//隐藏
registerserviceprocess(getcurrentprocessid, 0);//显示
◇[delphi]检测光驱符号
var drive:char;
cdromid:integer;
begin
for drive:='d' to 'z' do
begin
cdromid:=getdrivetype(pchar(drive+':\'));
if cdromid=5 then showmessage('你的光驱为:'+drive+'盘!');
end;
end;
◇[delphi]检测声卡
if auxgetnumdevs()<=0 then showmessage('no soundcard found!') else showmessage('any soundcard found!');
◇[delphi]在字符串网格中画图
stringgrid.ondrawcell事件
with stringgrid1.canvas do
draw(rect.left, rect.top, image1.picture.graphic);
◇[sql server]sql中代替like语句的另一种写法
比如查找用户名包含有"c"的所有用户, 可以用
use mydatabase
select * from table1 where username like'%c%"
下面是完成上面功能的另一种写法:
use mydatabase
select * from table1 where charindex('c',username)>0
这种方法理论上比上一种方法多了一个判断语句,即>0, 但这个判断过程是最快的, 我想信80%以上的运算都是花在查找字
符串及其它的运算上, 所以运用charindex函数也没什么大不了. 用这种方法也有好处, 那就是对%,等在不能直接用like
查找到的字符中可以直接在这charindex中运用, 如下:
use mydatabase
select * from table1 where charindex('%',username)>0
也可以写成:
use mydatabase
select * from table1 where charindex(char(37),username)>0
ascii的字符即为%
◇[delphi]sql显示多数据库/表
select distinct a.bianhao,a.xingming, b.gongzi from "jianjie.dbf" a, "gongzi.dbf" b
where a.bianhao=b.bianhao
◇[delphi]rfc(request for comment)相关
ietf(inte.net engineering task force)维护rfc文档http://www.ietf.cnri.reston.va.us
rfc882:报文头标结构
rfc1521:mime第一部分,传输报文方法
rfc1945:多媒体文档传输文档
◇[delphi]tnmuuprocessor的使用
var instream,outstream:tfilestream;
begin
instream:=tfilestream.create(infile.txt,fmopenread);
outstream:=tfilestream(outfile.txt,fmcreate);
nmuue.method:=uucode;{uuencode/decode}
//nmuue.method:=uumime;{mime}
nmuue.inputstream:=instream;
nmuue.outputstream:=outstream;
nmuue.encode;{编码处理}
//nmuue.decode;{解码处理}
instream.free;
outstream.free;
end;
◇[delphi]tfilestream的操作
//从文件流当前位置读count字节到缓冲区buffer
function read(var buffer;count:longint):longint;override;
//将缓冲区buffer读到文件流中
function write(const buffer;count:longint):longint;override;
//设置文件流当前读写指针为offset
function seek(offset:longint;origin:word):longint;override;
origin={sofrombeginning,sofromcurrent,sofromend}
//从另一文件流中当前位置复制count到当前文件流当前位置
function copyfrom(source:tstream;count:longint):longint;
//读指定文件到文件流
var myfstream:tfilestream;
begin
myfstream:=tfilestream.create(opendialog1.filename,fmopenread);
end;
[javascript]检测是否安装ie插件shockwave&quicktime
-----------------
关键字 本文所属关键字
相关 与本文相关文章
分类 所有文章关键字导航
源码编程相关
操作系统/服务器相关
标准 网站致力的规范