◇[DELPHI]網(wǎng)絡(luò)鄰居復(fù)制文件
uses shellapi;
copyfile(pchar('newfile.txt'),pchar('//computername/direction/targer.txt'),false);
◇[DELPHI]產(chǎn)生鼠標(biāo)拖動(dòng)效果
通過MouseMove事件、DragOver事件、EndDrag事件實(shí)現(xiàn),例如在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));
或者從注冊(cè)表中讀取,位置:
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 ttips.insert(1,'insert string at NO 2 line');
tips.savetofile('newfile.txt');
tips.free;
◇[DELPHI]簡(jiǎn)單的剪貼板操作
richedit1.selectall;
richedit1.copytoclipboard;
richedit1.cuttoclipboard;
edit1.pastefromclipboard;
◇[DELPHI]關(guān)于文件、目錄操作
Chdir('c:/abcdir');轉(zhuǎn)到目錄
Mkdir('dirname');建立目錄
Rmdir('dirname');刪除目錄
GetCurrentDir;//取當(dāng)前目錄名,無'/'
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 ... //系統(tǒng)
if (attr and faArchive)=faArchive then ... //存檔
if (attr and faHidden)=faHidden then ... //隱藏
◇[DELPHI]執(zhí)行程序外文件
WINEXEC//調(diào)用可執(zhí)行文件
winexec('command.com /c copy *.* c:/',SW_Normal);
winexec('start abc.txt');
ShellExecute或ShellExecuteEx//啟動(dòng)文件關(guān)聯(lián)程序
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:[email protected]','','',0);
◇[DELPHI]取得系統(tǒng)運(yùn)行的進(jìn)程名
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]關(guān)于匯編的嵌入
Asm End;
可以任意修改EAX、ECX、EDX;不能修改ESI、EDI、ESP、EBP、EBX。
◇[DELPHI]關(guān)于類型轉(zhuǎn)換函數(shù)
FloatToStr//浮點(diǎn)轉(zhuǎn)字符串
FloatToStrF//帶格式的浮點(diǎn)轉(zhuǎn)字符串
IntToHex//整數(shù)轉(zhuǎn)16進(jìn)制
TimeToStr
DateToStr
DateTimeToStr
FmtStr//按指定格式輸出字符串
formatDateTime('YYYY-MM-DD,hh-mm-ss',DATE);
◇[DELPHI]字符串的過程和函數(shù)
Insert(obj,target,pos);//字符串target插入在pos的位置。如插入結(jié)果大于target最大長(zhǎng)度,多出字符將被截掉。如Pos在255以外,會(huì)產(chǎn)生運(yùn)行錯(cuò)。例如,st:='Brian',則Insert('OK',st,2)會(huì)使st變?yōu)?BrOKian'。
Delete(st,pos,Num);//從st串中的pos(整型)位置開始刪去個(gè)數(shù)為Num(整型)個(gè)字符的子字串。例如,st:='Brian',則Delete(st,3,2)將變?yōu)锽rn。
Str(value,st);//將數(shù)值value(整型或?qū)嵭停┺D(zhuǎn)換成字符串放在st中。例如,a=2.5E4時(shí),則str(a:10,st)將使st的值為' 25000'。
Val(st,var,code);//把字符串表達(dá)式st轉(zhuǎn)換為對(duì)應(yīng)整型或?qū)嵭蛿?shù)值,存放在var中。St必須是一個(gè)表示數(shù)值的字符串,并符合數(shù)值常數(shù)的規(guī)則。在轉(zhuǎn)換過程中,如果沒有檢測(cè)出錯(cuò)誤,變量code置為0,否則置為第一個(gè)出錯(cuò)字符的位置。例如,st:=25.4E3,x是一個(gè)實(shí)型變量,則val(st,x,code)將使X值為25400,code值為0。
Copy(st.pos.num);//返回st串中一個(gè)位置pos(整型)處開始的,含有num(整型)個(gè)字符的子串。如果pos大于st字符串的長(zhǎng)度,那就會(huì)返回一個(gè)空串,如果pos在255以外,會(huì)引起運(yùn)行錯(cuò)誤。例如,st:='Brian',則Copy(st,2,2)返回'ri'。
Concat(st1,st2,st3……,stn);//把所有自變量表示出的字符串按所給出的順序連接起來,并返回連接后的值。如果結(jié)果的長(zhǎng)度255,將產(chǎn)生運(yùn)行錯(cuò)誤。例如,st1:='Brian',st2:=' ',st3:='Wilfred',則Concat(st1,st2,st3)返回'Brian Wilfred'。
Length(st);//返回字符串表達(dá)式st的長(zhǎng)度。例如,st:='Brian',則Length(st)返回值為5。
Pos(obj,target);//返回字符串obj在目標(biāo)字符串target的第一次出現(xiàn)的位置,如果target沒有匹配的串,Pos函數(shù)的返回值為0。例如,target:='Brian Wilfred',則Pos('Wil',target)的返回值是7,Pos('hurbet',target)的返回值是0。
◇[DELPHI]關(guān)于處理注冊(cè)表
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]關(guān)于鍵盤常量名
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.086net.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]判斷鼠標(biāo)按鍵
if GetAsyncKeyState(VK_LButton)<>0 then ... //左鍵
if GetAsyncKeyState(VK_MButton)<>0 then ... //中鍵
if GetAsyncKeyState(VK_RButton)<>0 then ... //右鍵
◇[DELPHI]設(shè)置窗體的最大顯示
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;
◇[雜類]隱藏共享文件夾
共享效果:可訪問,但不可見(在資源管理、網(wǎng)絡(luò)鄰居中)
取共享名為:direction$
訪問://computer/dirction/
◇[java Script]Java Script網(wǎng)頁常用效果
網(wǎng)頁60秒定時(shí)關(guān)閉
關(guān)閉窗口
關(guān)閉
定時(shí)轉(zhuǎn)URL
設(shè)為首頁
設(shè)為首頁
收藏本站
收藏本站
加入頻道
加入頻道
◇[DELPHI]隨機(jī)產(chǎn)生文本色
randomize;//隨機(jī)種子
memo1.font.color:=rgb(random(255),random(255),random(255));
◇[DELPHI]DELPHI5 UPDATE升級(jí)補(bǔ)丁序列號(hào)
1000003185
90X25fx0
◇[DELPHI]文件名的非法字符過濾
for i:=1 to length(s) do
if s[i] in ['/','/',':','*','?','<','>','|'] then
◇[DELPHI]轉(zhuǎn)換函數(shù)的定義及說明
datetimetofiledate (datetime:Tdatetime):longint; 將Tdatetime格式的日期時(shí)間值轉(zhuǎn)換成DOS格式的日期時(shí)間值
datetimetostr (datetime:Tdatetime):string; 將Tdatatime格式變量轉(zhuǎn)換成字符串,如果datetime參數(shù)不包含日期值,返回字符串日期顯示成為00/00/00,如果datetime參數(shù)中沒有時(shí)間值,返回字符串中的時(shí)間部分顯示成為00:00:00 AM
datetimetostring (var result string;
const format:string;
datetime:Tdatetime); 根據(jù)給定的格式字符串轉(zhuǎn)換時(shí)間和日期值,result為結(jié)果字符串,format為轉(zhuǎn)換格式字符串,datetime為日期時(shí)間值
datetostr (date:Tdatetime) 使用shortdateformat全局變量定義的格式字符串將date參數(shù)轉(zhuǎn)換成對(duì)應(yīng)的字符串
floattodecimal (var result:Tfloatrec;value:
extended;precision,decimals:
integer); 將浮點(diǎn)數(shù)轉(zhuǎn)換成十進(jìn)制表示
floattostr (value:extended):string 將浮點(diǎn)數(shù)value轉(zhuǎn)換成字符串格式,該轉(zhuǎn)換使用普通數(shù)字格式,轉(zhuǎn)換的有效位數(shù)為15位。
floattotext (buffer:pchar;value:extended;
format:Tfloatformat;precision,
digits:integer):integer; 用給定的格式、精度和小數(shù)將浮點(diǎn)值value轉(zhuǎn)換成十進(jìn)制表示形式,轉(zhuǎn)換結(jié)果存放于buffer參數(shù)中,函數(shù)返回值為存儲(chǔ)到buffer中的字符位數(shù),buffer是非0結(jié)果的字符串緩沖區(qū)。
floattotextfmt (buffer:pchar;value:extended;
format:pchar):integer 用給定的格式將浮點(diǎn)值value轉(zhuǎn)換成十進(jìn)制表示形式,轉(zhuǎn)換結(jié)果存放于buffer參數(shù)中,函數(shù)返回值為存儲(chǔ)到buffer中的字符位數(shù)。
inttohex (value:longint;digits:integer):
string; 將給定的數(shù)值value轉(zhuǎn)換成十六進(jìn)制的字符串。參數(shù)digits給出轉(zhuǎn)換結(jié)果字符串包含的數(shù)字位數(shù)。
inttostr (value:longint):string 將整數(shù)轉(zhuǎn)換成十進(jìn)制形式字符串
strtodate (const S:string):Tdatetime 將字符串轉(zhuǎn)換成日期值,S必須包含一個(gè)合法的格式日期的字符串。
strtodatetime (const S:string):Tdatetime 將字符串S轉(zhuǎn)換成日期時(shí)間格式,S必須具有MM/DD/YY HH:MM:SS[AM|PM]格式,其中日期和時(shí)間分隔符與系統(tǒng)時(shí)期時(shí)間常量設(shè)置相關(guān)。如果沒有指定AM或PM信息,表示使用24小時(shí)制。
strtofloat (const S:string):extended; 將給定的字符串轉(zhuǎn)換成浮點(diǎn)數(shù),字符串具有如下格式:
[+|-]nnn…[.]nnn…[<+|->
strtoint (const S:string):longint 將數(shù)字字符串轉(zhuǎn)換成整數(shù),字符串可以是十進(jìn)制或十六進(jìn)制格式,如果字符串不是一個(gè)合法的數(shù)字字符串,系統(tǒng)發(fā)生ECONVERTERROR異常
strtointdef (const S:string;default:
longint):longint; 將字符串S轉(zhuǎn)換成數(shù)字,如果不能將S轉(zhuǎn)換成數(shù)字,strtointdef函數(shù)返回參數(shù)default的值。
strtotime (const S:string):Tdatetime 將字符串S轉(zhuǎn)換成TDATETIME值,S具有HH:MM:SS[AM|PM]格式,實(shí)際的格式與系統(tǒng)的時(shí)間相關(guān)的全局變量有關(guān)。
timetostr (time:Tdatetime):string; 將參數(shù)TIME轉(zhuǎn)換成字符串。轉(zhuǎn)換結(jié)果字符串的格式與系統(tǒng)的時(shí)間相關(guān)常量的設(shè)置有關(guān)。
◇[DELPHI]程序不出現(xiàn)在ALT+CTRL+DEL
在implementation后添加聲明:
function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external 'KERNEL32.DLL';
RegisterServiceProcess(GetCurrentProcessID, 1);//隱藏
RegisterServiceProcess(GetCurrentProcessID, 0);//顯示
用ALT+DEL+CTRL看不見
◇[DELPHI]程序不出現(xiàn)在任務(wù)欄
uses windows
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]如何判斷撥號(hào)網(wǎng)絡(luò)是開還是關(guān)
if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then
showmessage('在線!')
else showmessage('不在線!');
◇[DELPHI]實(shí)現(xiàn)IP到域名的轉(zhuǎn)換
function GetDomainName(Ip:string):string;
var
pH:PHostent;
data:twsadata;
ii:dWord;
begin
WSAStartup($101, Data);
ii:=inet_addr(pchar(ip));
pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
if (ph<>nil) then
result:=pH.h_name
else
result:='';
WSACleanup;
end;
◇[DELPHI]處理“右鍵菜單”方法
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey:=HKEY_CLASSES_ROOT;
reg.OpenKey('*/shell/check/command', true);
reg.WriteString('', '"' + application.ExeName + '" "%1"');
reg.CloseKey;
reg.OpenKey('*/shell/diary', false);
reg.WriteString('', '操作(&C)');
reg.CloseKey;
reg.Free;
showmessage('DONE!');
end;
◇[DELPHI]發(fā)送虛擬鍵值ctrl V
procedure sendpaste;
begin
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0);
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);
end;
◇[DELPHI]當(dāng)前的光驅(qū)的盤符
procedure getcdrom(var cd:char);
var
str:string;
drivers:integer;
driver:char;
i,temp:integer;
begin
drivers:=getlogicaldrives;
temp:=(1 and drivers);
for i:=0 to 26 do
begin
if temp=1 then
begin
driver:=char(i+integer('a'));
str:=driver+':';
if getdrivetype(pchar(str))=drive_cdrom then
begin
cd:=driver;
exit;
end;
end;
drivers:=(drivers shr 1);
temp:=(1 and drivers);
end;
end;
◇[DELPHI]字符的加密與解密
function cryptstr(const s:string; stype: dword):string;
var
i: integer;
fkey: integer;
begin
result:='';
case stype of
0: setpass;
begin
randomize;
fkey := random($ff);
for i:=1 to length(s) do
result := result+chr( ord(s[i]) xor i xor fkey);
result := result + char(fkey);
end;
1: getpass
begin
fkey := ord(s[length(s)]);
for i:=1 to length(s) - 1 do
result := result+chr( ord(s[i]) xor i xor fkey);
end;
end;
□◇[DELPHI]向其他應(yīng)用程序發(fā)送模擬鍵
var
h: THandle;
begin
h := FindWindow(nil, '應(yīng)用程序標(biāo)題');
PostMessage(h, WM_KEYDOWN, VK_F9, 0);//發(fā)送F9鍵
end;
□◇[DELPHI]DELPHI 支持的DAO數(shù)據(jù)格式
td.Fields.Append(td.CreateField ('dbBoolean',dbBoolean,0));
td.Fields.Append(td.CreateField ('dbByte',dbByte,0));
td.Fields.Append(td.CreateField ('dbInteger',dbInteger,0));
td.Fields.Append(td.CreateField ('dbLong',dbLong,0));
td.Fields.Append(td.CreateField ('dbCurrency',dbCurrency,0));
td.Fields.Append(td.CreateField ('dbSingle',dbSingle,0));
td.Fields.Append(td.CreateField ('dbDouble',dbDouble,0));
td.Fields.Append(td.CreateField ('dbDate',dbDate,0));
td.Fields.Append(td.CreateField ('dbBinary',dbBinary,0));
td.Fields.Append(td.CreateField ('dbText',dbText,0));
td.Fields.Append(td.CreateField ('dbLongBinary',dbLongBinary,0));
td.Fields.Append(td.CreateField ('dbMemo',dbMemo,0));
td.Fields['ID'].Set_Attributes(dbAutoIncrField);//自增字段
□◇[DELPHI]DELPHI配置MS SQL 7和BDE步驟
第一步,配置ODBC:
先在ODBC 中設(shè)數(shù)據(jù)源,安裝過SQL Server7.0 后,ODBC中有一項(xiàng)"系統(tǒng)DSN"應(yīng)該有兩項(xiàng)
數(shù)據(jù)源,一個(gè)是MQIS,一個(gè)是LocalSever,任選一個(gè)選后點(diǎn)擊配置按鈕,不知你的SQL7.0
是不是安裝在本地機(jī)器上,如果是的話直接進(jìn)行下一步,如果不是,在服務(wù)器一欄中填上
Server,然后進(jìn)行下一步,填寫登錄ID 和密碼(登錄ID,和密碼是在SQL7.0中的用戶選項(xiàng)
中設(shè)的)。
第二步,配置BDE:
打開Delphi的BDE,然后點(diǎn)擊MQIS 或 LocalServer,就會(huì)提示用戶名和密碼,這和
ODBC的用戶名和密碼是一樣的,填上就行了。
第三步,配置程序:
如果用的是TTable,就在TTable的DatabaseName中選擇MQIS 或LocalServer,然后在
TableName中選擇Sale就行了,然后將Active改為True,Delphi彈出提示對(duì)話,填入用戶
名和密碼。
如果用的是TQuery,在TQuery上點(diǎn)擊右鍵,再擊"SQL Builder",這是以界面方式配置
SQL語句,或者在TQuery的SQL中填入SQL語句。最后,別忘了將Active改為True。
在運(yùn)行也可能配置TQuery,具體見Delphi幫助。
□◇[DELPHI]得到圖像上某一點(diǎn)的RGB值
procedure Tform1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
red,green,blue:byte ;
i:integer;
begin
i:= image1.Canvas.Pixels[x,y];
Blue:= GetBvalue(i);
Green:= GetGvalue(i):
Red:= GetRvalue(i);
Label1.Caption:=inttostr(Red);
Label2.Caption:=inttostr(Green);
Label3.Caption:=inttostr(Blue);
end;
□◇[DELPHI]關(guān)于日期格式分解轉(zhuǎn)換
var year,month,day:word;now2:Tdatatime;
now2:=date();
decodedate(now2,year,month,day);
lable1.Text :=inttostr(year)+'年'+inttostr(month)+'月'+inttostr(day)+'日';
◇[DELPHI]如何判斷當(dāng)前網(wǎng)絡(luò)連接方式
判斷結(jié)果是MODEM、局域網(wǎng)或是代理服務(wù)器方式。
uses wininet;
Function ConnectionKind :boolean;
var flags: dword;
begin
Result := InternetGetConnectedState(@flags, 0);
if Result then
begin
if (flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then
begin
showmessage('Modem');
end;
if (flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
begin
showmessage('LAN');
end;
if (flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then
begin
showmessage('Proxy');
end;
if (flags and INTERNET_CONNECTION_MODEM_BUSY)=INTERNET_CONNECTION_MODEM_BUSY then
begin
showmessage('Modem Busy');
end;
end;
end;
◇[DELPHI]如何判斷字符串是否是有效EMAIL地址
function IsEMail(EMail: String): Boolean;
var s: String;ETpos: Integer;
begin
ETpos:= pos('@', EMail);
if ETpos > 1 then
begin
s:= copy(EMail,ETpos+1,Length(EMail));
if (pos('.', s) > 1) and (pos('.', s) < length(s)) then
Result:= true else Result:= false;
end
else
Result:= false;
end;
◇[DELPHI]判斷系統(tǒng)是否連接INTERNET
需要引入U(xiǎn)RL.DLL中的InetIsOffline函數(shù)。
函數(shù)申明為:
function InetIsOffline(Flag: Integer): Boolean; stdcall; external 'URL.DLL';
然后就可以調(diào)用函數(shù)判斷系統(tǒng)是否連接到INTERNET
if InetIsOffline(0) then ShowMessage('not connected!')
else ShowMessage('connected!');
該函數(shù)返回TRUE如果本地系統(tǒng)沒有連接到INTERNET。
附:
大多數(shù)裝有IE或OFFICE97的系統(tǒng)都有此DLL可供調(diào)用。
InetIsOffline
BOOL InetIsOffline(
DWORD dwFlags,
);
◇[DELPHI]簡(jiǎn)單地播放和暫停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]取機(jī)器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]網(wǎng)絡(luò)下載文件
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]解析服務(wù)器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的自動(dòng)完成
{'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]如何清空一個(gè)目錄
function EmptyDirectory(TheDirectory :String ; Recursive : Boolean) :
Boolean;
var
SearchRec : TSearchRec;
Res : Integer;
begin
Result := False;
TheDirectory := NormalDir(TheDirectory);
Res := FindFirst(TheDirectory + '*.*', faAnyFile, SearchRec);
try
while Res = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
if ((SearchRec.Attr and faDirectory) > 0) and Recursive
then begin
EmptyDirectory(TheDirectory + SearchRec.Name, True);
RemoveDirectory(PChar(TheDirectory + SearchRec.Name));
end
else begin
DeleteFile(PChar(TheDirectory + SearchRec.Name))
end;
end;
Res := FindNext(SearchRec);
end;
Result := True;
finally
FindClose(SearchRec.FindHandle);
end;
end;
◇[DELPHI]安裝程序如何添加到Uninstall列表
操作注冊(cè)表,如下:
1.在HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall鍵下建立一個(gè)主鍵,名稱任意。
例HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/MyUninstall
2.在HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/MyUnistall下鍵兩個(gè)串值,
這兩個(gè)串值的名稱是特定的:DisplayName和UninstallString。
3.給串DisplayName賦值為顯示在“刪除應(yīng)用程序列表”中的名稱,如'Aiming Uninstall one';
給串UninstallString賦值為執(zhí)行的刪除命令,如 C:/WIN97/uninst.exe -f"C:/TestPro/aimTest.isu"
◇[DELPHI]截獲WM_QUERYENDsession關(guān)機(jī)消息
type
Tform1 = class(Tform)
procedure WMQueryEndSession(var Message: TWMQueryEndSession); message WM_QUERYENDSESSION;
procedure CMEraseBkgnd(var Message:TWMEraseBkgnd);Message WM_ERASEBKGND;
private
{ Private declarations }
public
{ Public declarations }
end;
procedure Tform1.WMQueryEndSession(var Message: TWMQueryEndSession);
begin
Showmessage('computer is about to shut down');
end;
◇[DELPHI]獲取網(wǎng)上鄰居
procedure getnethood();//NT做服務(wù)器,WIN98上調(diào)試通過。
var
a,i:integer;
errcode:integer;
netres:array[0..1023] of netresource;
enumhandle:thandle;
enumentries:dword;
buffersize:dword;
s:string;
mylistitems:tlistitems;
mylistitem:tlistitem;
alldomain:tstrings;
begin //listcomputer is a listview to list all computers;controlcenter is a form.
alldomain:=tstringlist.Create ;
with netres[0] do begin
dwscope :=RESOURCE_GLOBALNET;
dwtype :=RESOURCETYPE_ANY;
dwdisplaytype :=RESOURCEDISPLAYTYPE_DOMAIN;
dwusage :=RESOURCEUSAGE_CONTAINER;
lplocalname :=nil;
lpremotename :=nil;
lpcomment :=nil;
lpprovider :=nil;
end; // 獲取所有的域
errcode:=wnetopenenum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,@netres[0],enumhandle);
if errcode=NO_ERROR then begin
enumentries:=1024;
buffersize:=sizeof(netres);
errcode:=wnetenumresource(enumhandle,enumentries,@netres[0],buffersize);
end;
a:=0;
mylistitems :=controlcenter.lstcomputer.Items ;
mylistitems.Clear ;
while (string(netres[a].lpprovider)<>'') and (errcode=NO_ERROR) do
begin
alldomain.Add (netres[a].lpremotename);
a:=a+1;
end;
wnetcloseenum(enumhandle);
// 獲取所有的計(jì)算機(jī)
mylistitems :=controlcenter.lstcomputer.Items ;
mylistitems.Clear ;
for i:=0 to alldomain.Count-1 do
begin
with netres[0] do begin
dwscope :=RESOURCE_GLOBALNET;
dwtype :=RESOURCETYPE_ANY;
dwdisplaytype :=RESOURCEDISPLAYTYPE_SERVER;
dwusage :=RESOURCEUSAGE_CONTAINER;
lplocalname :=nil;
lpremotename :=pchar(alldomain[i]);
lpcomment :=nil;
lpprovider :=nil;
end;
ErrCode:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,RESOURCEUSAGE_CONTAINER,@netres[0],EnumHandle);
if errcode=NO_ERROR then
begin
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(EnumHandle,EnumEntries,@NetRes[0],BufferSize);
end;
a:=0;
while (string(netres[a].lpprovider)<>'') and (errcode=NO_ERROR) do
begin
mylistitem :=mylistitems.Add ;
mylistitem.ImageIndex :=0;
mylistitem.Caption :=uppercase(stringreplace(string(NetRes[a].lpremotename),'//','',[rfReplaceAll]));
a:=a+1;
end;
wnetcloseenum(enumhandle);
end;
end;
◇[DELPHI]獲取某一計(jì)算機(jī)上的共享目錄
procedure getsharefolder(const computername:string);
var
errcode,a:integer;
netres:array[0..1023] of netresource;
enumhandle:thandle;
enumentries,buffersize:dword;
s:string;
mylistitems:tlistitems;
mylistitem:tlistitem;
mystrings:tstringlist;
begin
with netres[0] do begin
dwscope :=RESOURCE_GLOBALNET;
dwtype :=RESOURCETYPE_DISK;
dwdisplaytype :=RESOURCEDISPLAYTYPE_SHARE;
dwusage :=RESOURCEUSAGE_CONTAINER;
lplocalname :=nil;
lpremotename :=pchar(computername);
lpcomment :=nil;
lpprovider :=nil;
end; // 獲取根結(jié)點(diǎn)
errcode:=wnetopenenum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK,RESOURCEUSAGE_CONTAINER,@netres[0],enumhandle);
if errcode=NO_ERROR then
begin
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(EnumHandle,EnumEntries,@NetRes[0],BufferSize);
end;
wnetcloseenum(enumhandle);
a:=0;
mylistitems:=controlcenter.lstfile.Items ;
mylistitems.Clear ;
while (string(netres[a].lpprovider)<>'') and (errcode=NO_ERROR) do
begin
with mylistitems do
begin
mylistitem:=add;
mylistitem.ImageIndex :=4;
mylistitem.Caption :=extractfilename(netres[a].lpremotename);
end;
a:=a+1;
end;
end;
◇[DELPHI]得到硬盤序列號(hào)
var SerialNum : pdword; a, b : dword; Buffer : array [0..255] of char;
begin
if GetVolumeInformation('c:/', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then Label1.Caption := IntToStr(SerialNum^);
end;
1.關(guān)于MDI主窗體背景新解
在Form中添加Image控件
設(shè)BMP圖象
name為 IMG_BK
在Foem的Create事件中寫入
Self.brush.bitmap:=img_bk.picture.bitmap;
2.在標(biāo)題欄處畫VCL控件(一行解決問題!!!)
在 form 的onpaint 事件中
控件.pointto(getdc(0),left,top);
3 Edit 中只輸入數(shù)字
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
4.類似MDI方式新解
在要設(shè)置child的oncreate方式下寫入:
self.parent:='要設(shè)置為mainform的Form';
5. 屏幕的Refresh(只需一行!)
RedrawWindow(0,nil,0,RDW_ERASE or RDW_INVALIDATE or RDW_ALLCHILDREN);
| |
--- ----
handle RGN(可刷新局部屏幕)
6.類似DOS下的CLS指令的WINDOWS指令!
paintdesktop(getdc(0));
7.擴(kuò)展控件新功能
在編程中 ,我們經(jīng)常要控制控件的動(dòng)作,但該控件又沒有提供該方法
這時(shí) ,可通過發(fā)消息給該控件 ,以達(dá)到我們的目的!
如:
button1.perform(wm_keydown,13,0);
listbox1.perform(wm_vscroll,sb_linedown,0);
等等 可少去 重載之苦!!!!!
8.閃爍標(biāo)題如打印機(jī)超時(shí)(一行)
form 放一timer 控件
time 事件 中 寫入 ;
Flashwindow(application.handle,true);
9.在桌面上加個(gè)VCL控件!(不是畫的,不可refresh)
windows.setparent(控件.handle,0);
注: 想放哪都行 (如'開始處狀態(tài)欄')
10.關(guān)于 '類似MDI方式新解(一行就行!!!!)'的修正
windows.setparent(self.handle,'要設(shè)置為mainform的Form');
11 普通Form象MDI中mainform始終在最底層
SetActiveWindow(0);
或 SetwindowPos(...);
12 執(zhí)行下列語句開始Windows屏幕保護(hù)程序
SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_SCREENSAVE,0);
13 button 的 caption 多行顯示:
SetWindowLong(Button1.handle, GWL_STYLE,
GetWindowlong(Button1.Handle, GWL_STYLE) or
BS_MULTILINE);
必要時(shí)加上 Button1.Invalidate;
14.整死windows98 :)
asm int $19 end
Q: 怎么來改變ListBox的字體呢?就修改其中的一行。
A: 先把ListBox1.Style 設(shè)成lbOwnerDrawFixed
然后在 OnDrawItem 事件下寫下如下代碼
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
Offset: Integer;
begin
Offset := 2;
with (Control as TListBox).Canvas do begin
FillRect(Rect);
if Index = 2 then begin
Font.Name := 'Fixedsys';
Font.Color := clRed;
Font.Size := 12;
end else begin
Font.Name := 'Arial';
Font.Color := clBlack;
Font.Size := 8;
end;
if odSelected in State then begin
Font.Color := clWhite;
end;
TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]);
end;
end;
Q:怎么在RichEdit里面插入圖片?
A: 請(qǐng)到這里來看看會(huì)找到答案
http://www.undu.com/Articles/991107c.html
Q:怎么才能目錄呢?
A:我來。
uses ShellAPI;
procedure DeleteFiles(Source: string);
var
FO: TShFileOpStruct;
begin
FillChar(FO,SizeOf(FO),#0);
FO.Wnd := Form1.Handle;
FO.wFunc := FO_DELETE;
FO.pFrom := PChar(Source);
ShFileOperation(FO);
end;
procedure EmptyDirectory(Path: String);
begin
if DirectoryExists(Path) then
begin
DeleteFiles(Path+'/*');
end
else
ForceDirectories(Path);
end;
Q:如何映射網(wǎng)絡(luò)驅(qū)動(dòng)器?
比如我要把file://Server/sys映射為F盤。我需要一個(gè)函數(shù)比如
給出輸入?yún)?shù)為file://server/sys/home/bruno給我的返回值是F:/home/bruno
A:
Function UNCToDrive(UNCPath: STring): STring;
var
DriveNum: Integer;
DriveChar: Char;
DriveBits: set of 0..25;
StartSTr,TestStr: STring;
begin
result := UNCPath;
StartSTr := UNCPath;
Integer(DriveBits) := GetLogicalDrives;
for DriveNum := 0 to 25 do
begin
if (DriveNum in DriveBits) then begin
DriveChar := Char(DriveNum + Ord('A'));
TestSTr := ExpandUNCFileName(DriveChar+':/');
If TEstStr <> '' then
If Pos(Uppercase(TestSTr),Uppercase(STartSTr)) > 0 then
begin
Delete(StartSTr,1,Length(TestSTr));
result := DriveChar+':/'+StartSTr;
break;
end;
end;
end;
end;
Q:我有一些特殊語言的字體來用,它們存儲(chǔ)在我的EXE文件里,但是兩點(diǎn)。
* 我不想放到font文件夾里
* 我不想從EXE文件里面提取出來
如果可能,請(qǐng)告訴我。
因?yàn)椋业淖煮w是自己做的不是windows自帶的,我想保護(hù)自己的東西。
A:不太可能,必須提取出來。你可以使用這個(gè)保護(hù)過程來保護(hù)你的文件不被修改和刪除。
在EXE執(zhí)行的時(shí)候把字體放到臨時(shí)文件夾里,結(jié)束的時(shí)候刪除它。
function ProtectFile(sFilename : string) : hFile;
var
hf: hFile;
lwHFileSize, lwFilesize: longword;
ofs : TOFStruct;
begin
if FileExists(sFilename) then
begin
hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE);
if hf <> 0 then
begin
lwFilesize := GetFileSize(hf, @lwHFileSize);
if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then
Result := hf else Result := 0;
end
else Result := 0;
end
else Result := 0;
end;
//..
var
ResS: TResourceStream;
TempPath: array [0..MAX_PATH] of Char;
TempDir: string;
begin
GetTempPath(Sizeof(TempPath), TempPath);
TempDir := StrPas(Path);
ResS := TResourceStream.Create(hInstance, 'SOME_FONT', 'RT_FONT');
ResS.SavetoFile(TempDir+'some_font.ttf');
ResS.Free;
AddFontResource(TempDir+'some_font.ttf');
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
ProtectFile(TempDir+'some_font.ttf');
end;
Q:如何得到當(dāng)前的ProgramFiles得路徑?
A:用讀寫注冊(cè)表的方法就可以做到。
代碼如下:
uses registry;
procedure TForm1.Button1Click(Sender: TObject);
var
reg:TRegistry;
begin
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion',false) then
begin
edit1.Text:=reg.ReadString('ProgramFilesDir');
reg.CloseKey;
reg.Free;
end;
end;
Q:如何在Jpg圖像上寫上字?
A:這里有個(gè)代碼。
hmm, here's a sample with help of Bitmap, you can chance the brush style of canvas to bsClear to make the text transparent
uses
Jpeg;
procedure TForm1.Button1Click(Sender: TObject);
var
Bmp : TBitmap;
Jpg : TJpegImage;
begin
try
Bmp := TBitmap.Create;
Jpg := TjpegImage.Create;
Jpg.LoadFromFile('c:/img.jpg');
Bmp.Assign(Jpg);
Bmp.Canvas.Brush.Style := bsClear;
Bmp.Canvas.Font.Color := clYellow;
Bmp.Canvas.TextOut(10,10,'Hello World');
Jpg.Assign(Bmp);
Jpg.SaveToFile('c:/img2.jpg');
finally
bmp.Free;
jpg.Free;
end;
end;
Q:怎么用delphi修改文件的時(shí)間呢?
在windows下,屬性里面有三個(gè)日起,創(chuàng)建,修改,存儲(chǔ)。我怎么來修改啊?
A:Here is the excerpt from the Jedi Code Library. If it is not complete then get the JCL.
type
// indicates the file time to set, used by SetFileTimesHelper and SetDirTimesHelper
TFileTimes = (ftLastaccess, ftLastWrite, ftCreation);
function SetFileTimesHelper(const FileName: string; const DateTime: TDateTime; Times: TFileTimes): Boolean;
var
Handle: THandle;
FileTime: TFileTime;
SystemTime: TSystemTime;
begin
Result := False;
Handle := CreateFile(PChar(FileName), GENERIC_WRITE, FILE_SHARE_READ, nil,
OPEN_EXISTING, 0, 0);
if Handle <> INVALID_HANDLE_VALUE then
try
//SysUtils.DateTimeToSystemTime(DateTimeToLocalDateTime(DateTime), SystemTime);
SysUtils.DateTimeToSystemTime(DateTime, SystemTime);
if Windows.SystemTimeToFileTime(SystemTime, FileTime) then
begin
case Times of
ftLastAccess:
Result := SetFileTime(Handle, nil, @FileTime, nil);
ftLastWrite:
Result := SetFileTime(Handle, nil, nil, @FileTime);
ftCreation:
Result := SetFileTime(Handle, @FileTime, nil, nil);
end;
end;
finally
CloseHandle(Handle);
end;
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastAccess(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastAccess);
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastWrite(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastWrite);
end;
//--------------------------------------------------------------------------------------------------
function SetFileCreation(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftCreation);
end;
google上的有關(guān)delphi得網(wǎng)址:
http://directory.google.com/Top/Computers/Programming/Languages/Delphi/?tc=1
yahoo上有關(guān)delphi得網(wǎng)址
http://dir.yahoo.com/Computers_and_Internet/Programming_and_Development/Languages/Delphi/
刪掉程序自己的exe文件
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
F:TextFile;
begin
AssignFile(F,'delself.bat');
Rewrite(F);{F為TextFile類型}
WriteLn(F,'del '+ExtractFileName(Application.ExeName));
WriteLn(F,'del %0'); //刪除自己delself.bat
CloseFile(F);
WinExec('delself.bat',SW_HIDE);
end;
if ord(s[9])>128 then
ShowMessage('該位置字符是漢字');
漢字是雙字節(jié)的
更改系統(tǒng)時(shí)間格式:
var
str: string;
begin
str := 'yyyy-mm-dd';
if SetLocaleInfoa(LOCALE_SYSTEM_DEFAULT, LOCALE_SLONGDATE, PChar(str)) then
begin
showmessage('更改日期格式成功');
end;
end;
休息一分鐘:
var
I:integer;
begin
i:=gettickcount;
while (Gettickcount-i)<=10000 do
application.ProcessMessages;//保證消息循環(huán)
end;
取主文件名:
function retuFileName(const FileName: string): string;
var
I: Integer;
begin
I := LastDelimiter('.', FileName);
Result := Copy(FileName, 1, i-1);
end;
(1).按下ctrl和其它鍵之后發(fā)生一事件。
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (key =67) then
showmessage('keydown Ctrl+C');
end;
(2).Dbgrid中用Enter鍵代替Tab鍵.
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
if ActiveControl = DBGrid1 then
begin
TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1;
Key := #0;
end;
end;
(3).Dbgrid中選擇多行發(fā)生一事件。
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
bookmarklist:Tbookmarklist;
bookmark:tbookmarkstr;
begin
bookmark:=adoquery1.Bookmark;
bookmarklist:=dbgrid1.SelectedRows;
try
begin
for i:=0 to bookmarklist.Count-1 do
begin
adoquery1.Bookmark:=bookmarklist[i];
with adoquery1 do
begin
edit;
fieldbyname('mdg').AsString:=edit2.Text;
post;
end;
end;
end;
finally
adoquery1.Bookmark:=bookmark;
end;
end;
(4).Form的一個(gè)出現(xiàn)效果。
procedure TForm1.Button1Click(Sender: TObject);
var
r:thandle;
i:integer;
begin
for i:=1 to trunc(width/1.414) do
begin
r:=CreateEllipticRgn(trunc(width/2)-i,trunc(height/2)-i,trunc(width/2)+i,trunc(height/2)+i);
SetWindowRgn(handle,r,true);
Application.ProcessMessages;
sleep(1);
end;
end;
(5).用Enter代替Tab在編輯框中移動(dòng)隹點(diǎn)。
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
if not (Activecontrol is Tmemo) then
begin
key:=#0;
keybd_event(vk_tab,mapvirtualkey(vk_tab,0),0,0);
end;
end;
end;
(6).Progressbar加上色彩。
const
{$EXTERNALSYM PBS_MARQUEE}
PBS_MARQUEE = 08;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
CommCtrl;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Set the Background color to teal
Progressbar1.Brush.Color := clTeal;
// Set bar color to yellow
SendMessage(ProgressBar1.Handle, PBM_SETBARCOLOR, 0, clYellow);
end;
(7).住點(diǎn)移動(dòng)時(shí)編輯框色彩不同。
procedure TForm1.Edit1Enter(Sender: TObject);
begin
(sender as tedit).Color:=clred;
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
(sender as tedit).Color:=clwhite;
end;
(8).備份和恢復(fù)
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
try
adoconnection1.Connected:=False;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;'+
'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False';
adoconnection1.Connected:=True;
with adoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('Backup DataBase sfa to disk ='''+opendialog1.FileName+'''');
ExecSQL;
end;
except
ShowMessage('±?·Yê§°ü');
Exit;
end;
end;
Application.MessageBox('1§?2?ú£?êy?Y±?·Y3é1|','ìáê?',MB_OK + MB_ICONINFORMATION);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
try
adoconnection1.Connected:=false;
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;'+
'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False';
adoconnection1.Connected:=true;
with adoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('Restore DataBase sfa from disk ='''+opendialog1.FileName+'''');
ExecSQL;
end;
except
ShowMessage('???′ê§°ü');
Exit;
end;
end;
Application.MessageBox('1§?2?ú£?êy?Y???′3é1|','ìáê?',MB_OK + MB_ICONINFORMATION);
end;
(9).查找局域網(wǎng)上的sqlserver報(bào)務(wù)器。
uses Comobj;
procedure TForm1.Button1Click(Sender: TObject);
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
sRetValue:String;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
nServers:=ServerList.Count;
for i := 1 to nservers do
ListBox1.Items.Add(ServerList.Item(i));
SQLServer:=NULL;
serverList:=NULL;
end;
(10).窗體打開時(shí)的淡入效果。
procedure TForm1.FormCreate(Sender: TObject);
begin
AnimateWindow (Handle, 400, AW_CENTER);
end;
(11).動(dòng)態(tài)創(chuàng)建窗體。
procedure TForm1.Button1Click(Sender: TObject);
begin
try
form2:=Tform2.Create(self);
form2.ShowModal;
finally
form2.Free;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
form1:=nil;
end;
(12).復(fù)制文件。
procedure TForm1.Button1Click(Sender: TObject);
begin
try
copyfileA(pchar('C:/AAA.txt'),pchar('D:/AAA.txt'),false);
except
showmessage('sfdsdf');
end;
end;
(13).復(fù)制文件夾。
uses shellAPI;
procedure TForm1.Button1Click(Sender: TObject);
var
lpFileOp: TSHFileOpStruct;
begin
with lpFileOp do
begin
Wnd:=Self.Handle;
wfunc:=FO_COPY;
pFrom:=pchar('C:/AAA');
pTo:=pchar('D:/AAA');
fFlags:=FOF_ALLOWUNDO;
hNameMappings:=nil;
lpszProgressTitle:=nil;
fAnyOperationsAborted:=True;
end;
if SHFileOperation(lpFileOp)<>0 then
ShowMessage('刪除失敗');
end;
(14).改變Dbgrid的選定色。
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if gdSelected in state then
SetBkColor(dbgrid1.canvas.handle,clgreen)
else
setbkcolor(dbgrid1.canvas.handle,clwhite);
dbgrid1.Canvas.TextRect(rect,0,0,field.AsString);
dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString);
end;
(15).檢測(cè)系統(tǒng)是否已安裝了ADO。
uses registry;
function Tform1.ADOInstalled:Boolean;
var
r:TRegistry;
s:string;
begin
r := TRegistry.create;
try
with r do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey( '/ADODB.Connection/CurVer', false );
s := ReadString('');
if s <> '' then Result := True
else Result := False;
CloseKey;
end;
finally
r.free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ADOInstalled then showmessage('this computer has installed ADO');
end;
(16).取利主機(jī)的ip地址。
uses winsock;
procedure TForm1.Button1Click(Sender: TObject);
var
IP:string;
IPstr:String;
buffer:array[1..32] of char;
i:integer;
WSData:TWSAdata;
Host:PHostEnt;
begin
if WSAstartup(2,WSData)<>0 then
begin
showmessage('WS2_32.DLL3?ê??ˉê§°ü.');
exit;
end;
try
if GetHostname(@buffer[1],32)<>0 then
begin
showmessage('??óDμ?μ??÷?ú??.');
exit;
end;
except
showmessage('??óD3é1|·μ???÷?ú??');
exit;
end;
Host:=GetHostbyname(@buffer[1]);
if Host=nil then
begin
showmessage('IPμ??·?a??.');
exit;
end
else
begin
edit2.Text:=Host.h_name;
edit3.Text:=chr(host.h_addrtype+64);
for i:=1 to 4 do
begin
IP:=inttostr(ord(host.h_addr^[i-1]));
if i<4 then
ipstr:=ipstr+IP+'.'
else
edit1.Text:=ipstr+ip;
end;
end;
WSACleanup;
end;
(17).取得計(jì)算機(jī)名。
function tform1.get_name:string;
var ComputerName: PChar; size: DWord;
begin
GetMem(ComputerName,255);
size:=255;
if GetComputerName(ComputerName,size)=False then
result:=''
else
result:=ComputerName;
FreeMem(ComputerName);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=get_name;
end;
(18).取得硬盤序列號(hào)。
function tform1.GetHDSerialNumber: LongInt;
{$IFDEF WIN32}
var
pdw : pDWord;
mc, fl : dword;
{$ENDIF}
begin
{$IfDef WIN32}
New(pdw);
GetVolumeInformation('c:/',nil,0,pdw,mc,fl,nil,0);
Result := pdw^;
dispose(pdw);
{$ELSE}
Result := GetWinFlags;
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=inttostr(gethdserialnumber);
end;
(19).限定光標(biāo)移動(dòng)范圍。
procedure TForm1.Button1Click(Sender: TObject);
var
rect1:trect;
begin
rect1:=button2.BoundsRect;
mapwindowpoints(handle,0,rect1,2);
clipcursor(@rect1);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
screenrect:trect;
begin
screenrect:=rect(0,0,screen.Width,screen.Height);
clipcursor(@screenrect);
end;
(20).限制edit框只能輸入數(shù)字。
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',#8]) then
begin
key:=#0;
Messagebeep(0);
end;
end;
(21).dbgrid中根據(jù)任一條件某一格變色。
procedure TForm_main.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if (trim(DataModule1.ADOQuery1.FieldByName('dczt').AsString)='OK') then
begin
if datacol=6 then
begin
DbGrideh1.Canvas.Brush.Color:=clGradientActiveCaption;
DbGrideh1.DefaultDrawColumnCell(Rect,datacol,column,state);
end;
end;
end;
(22).打開word文件。
procedure TfjfsglForm.SpeedButton4Click(Sender: TObject);
var
MSWord: Variant;
str:string;
begin
if trim(DataModule1.adoquery27.fieldbyname('fjmc').asstring)<>'' then
begin
str:=trim(DataModule1.ADOQuery27.fieldbyname('fjmc').AsString);
MSWord:= CreateOLEObject('Word.Application');//
MSWord.Documents.Open('d:/Program Files/Common Files/Sfa/'+str, True);//
MSWord.Visible:=1;//
str:='';
MSWord.ActiveDocument.Range(0, 0);//
MSWord.ActiveDocument.Range.InsertAfter(str);//?úWord?D???ó×?·?'Title'
MSWord.ActiveDocument.Range.InsertParagraphAfter;
end
else
showmessage('');
end;
(23).word文件傳入和傳出數(shù)據(jù)庫。
uses IdGlobal;
procedure TdjhyForm.SpeedButton2Click(Sender: TObject);
var
sfilename:string;
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;
DataModule1.ADOQuery14.Edit;
DataModule1.ADOQuery14.FieldByName('word').AsString:=blobcontenttostring(sfilename);
DataModule1.ADOQuery14.Post;
end;
end;
procedure TdjhyForm.SpeedButton1Click(Sender: TObject);
var
sfilename:string;
bs:Tadoblobstream;
begin
bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word')),bmread);
try
sfilename:=extractfilepath(application.ExeName)+trim(DataModule1.adoquery14.fieldbyname('hybh').AsString);
sfilename:=sfilename+'.'+'doc';
bs.SaveToFile(sfilename);
try
djhyopenform:=Tdjhyopenform.Create(self);
djhyopenform.olecontainer1.CreateObjectFromFile(sfilename,false);
djhyopenform.OleContainer1.Iconic:=true;
&n
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注