当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: ◇[DELPHI]网络邻居复制文件uses shellapi;c
 

 

    摘要:利用vfi提高delphi程序的重用性摘要:程序重用性是软件质量的重要指标之一,提高重用性对于减少程序潜在缺陷,提高程序开发效率,降低维护成本具有重要的影响。本文针对delphi所提供的vfi,给出了具体应用vfi来提高程序重用性的实例。该实例表明,使用vfi可以极大地简化程序代码,并保持界面的一致性,提高程序开发效率。关键词:重用性、delphi、vfi1 引言 软件重用(software re......
    摘要:最近上班总有一些零散的事情要处理,要负责同事们电脑的日常维护,以及一些软硬件方面的问题。所以就没有太多的时间用来读书。而且更加郁闷的是,上周末由于访问一个网站造成电脑中毒,尝试了很多方法清除都未能成功。病毒文件在安全模式下删除后重新启动又恢复了,修改注册表中的run也无效,几番修改也告失败。最终在判断方面出现错误,将系统文件误认为病毒文件删除,导致系统无法启动。最后只好ghost回去,无奈人太懒,......


DELPHI基础开发技巧

◇[delphi]网络邻居复制文件

uses shellapi; 【程序编程相关:快速导出数据到Excel(一):利用剪贴

【推荐阅读:用Delphi实现动态代理(2):设计说

copyfile(pchar(newfile.txt),pchar(//computername/direction/targer.txt),false); 【扩展信息:用Delphi实现动态代理(1):概述

◇[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.lineto(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(hcurrnetwindow,@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;


...   下一页
 ·delphi7中存储unicode的bug?     »显示摘要«
    摘要:delphi7中存储unicode的bug? 近日,在用delphi7做unicode的程序时发现了这样一个问题,就是使用tadocommand组件执行sql语句时,如果sql语句中有unicode字符,存储在数据库里会出现乱码,使用ttntadoquery也是一样(使用参数方式不会出现乱码,这里只讨论纯sql的方式)。但是tadocommand本身是支持widestring的呀,commandt......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE