◇[DELPHI] Network neighbor copy files
uses shellapi;
copyfile(pchar('newfile.txt'),pchar('//computername/direction/targer.txt'),false);
◇[DELPHI] generates mouse drag effect
Implemented through MouseMove event, DragOver event, and EndDrag event, such as LABEL on PANEL:
var xpanel,ypanel,xlabel,ylabel:integer;
PANEL's MouseMove event: xpanel:=x;ypanel:=y;
PANEL's DragOver event: xpanel:=x;ypanel:=y;
LABEL's MouseMove event: xlabel:=x;ylabel:=y;
LABEL's EndDrag event: label.left:=xpanel-xlabel;label.top:=ypanel-ylabel;
◇[DELPHI] Obtain the WINDOWS directory
uses shellapi;
var windir:array[0..255] of char;
getwindir directory(windir,sizeof(windir));
Or read from the registry, location:
HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion
SystemRoot key, get: C:/WINDOWS
◇[DELPHI] Draw lines on form or other containers
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] string list usage
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] Simple clipboard operation
richedit1.selectall;
richedit1.copytoclipboard;
richedit1.cuttoclipboard;
edit1.pastefromclipboard;
◇[DELPHI] About file and directory operations
Chdir('c:/abcdir'); Go to directory
Mkdir('dirname');Create directory
Rmdir('dirname'); delete directory
GetCurrentDir;//Get the current directory name, no '/'
Getdir(0,s);//Get the working directory name s:='c:/abcdir';
Deletfile('abc.txt');//Delete the file
Renamefile('old.txt','new.txt');//File name change
ExtractFilename(filelistbox1.filename);//Get the file name
ExtractFileExt(filelistbox1.filename);//Take the file suffix
◇[DELPHI] Process file attributes
attr:=filegetattr(filelistbox1.filename);
if (attr and faReadonly)=faReadonly then ... //Readonly only
if (attr and faSysfile)=faSysfile then ... //System
if (attr and faArchive)=faArchive then ... //Archive
if (attr and faHidden)=faHidden then ... //Hide
◇[DELPHI] Execute external program files
WINEXEC//Calling executable file
winexec('command.com /c copy *.* c:/',SW_Normal);
winexec('start abc.txt');
ShellExecute or ShellExecuteEx// Start the file association program
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] Obtain the process name of the system running
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] Embedding on assembly
Asm End;
EAX, ECX, EDX can be modified at will; ESI, EDI, ESP, EBP, and EBX cannot be modified.
◇[DELPHI] About type conversion function
FloatToStr//Floatpoint to string
FloatToStrF//Floatpoint to string with format
IntToHex//Integer to hexadecimal
TimeToStr
DateToStr
DateTimeToStr
FmtStr//Output string in the specified format
formatDateTime('YYYY-MM-DD,hh-mm-ss',DATE);
◇[DELPHI] Process and Functions of Strings
Insert(obj,target,pos);//The string target is inserted at the position of pos. If the insertion result is greater than the maximum length of the target, extra characters will be cut off. If Pos is outside 255, it will cause a running error. For example, st:='Brian', then Insert('OK',st,2) will make st become 'BrOKian'.
Delete(st,pos,Num);//Drop out substrings with a number of Num (integral) characters from the pos position in the st string. For example, st:='Brian', then Delete(st,3,2) will become Brn.
Str(value,st);//Convert the numeric value (integral or real) into a string and put it in st. For example, when a=2.5E4, str(a:10,st) will make the value of st be '25000'.
Val(st,var,code);//Convert the string expression st to the corresponding integer or real value and store it in var. St must be a string representing numeric values and comply with the rules of numeric constants. During the conversion process, if no error is detected, the variable code is set to 0, otherwise it is set to the position of the first error character. For example, st:=25.4E3, x is a real variable, then val(st,x,code) will make X value 25400 and code value 0.
Copy(st.pos.num);//Returns a substring that starts at a position in the st string at pos (integral) and contains num (integral) characters. If pos is greater than the length of the st string, an empty string will be returned. If pos is outside 255, it will cause a running error. For example, st:='Brian', then Copy(st,2,2) returns 'ri'.
Concat(st1,st2,st3...,stn);//Connect all the strings represented by the arguments in the order given and return the connected value. If the result is length 255, a running error will be generated. For example, st1:='Brian',st2:=' ',st3:='Wilfred', then Concat(st1,st2,st3) returns 'Brian Wilfred'.
Length(st);//Returns the length of the string expression st. For example, st:='Brian', then the Length(st) return value is 5.
Pos(obj,target);//Returns the position where the string obj first appears in the target string target. If the target does not match the string, the return value of the Pos function is 0. For example, target:='Brian Wilfred', then the return value of Pos('Wil', target) is 7, and the return value of Pos('hurbet', target) is 0.
◇[DELPHI] About processing the registry
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] About keyboard constant names
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)
AZ: $41(65)--$5A(90)
0-9: $30(48)--$39(57)
◇[DELPHI] Preliminary judgment program native language
DOS tips for DELPHI software: This PRogram Must Be Run Under Win32.
DOS tips for VC++ software: This Program Cannot Be Run In DOS Mode.
◇[DELPHI] Operation Cookies
response.cookies("name").domain:='http://www.086net.com';
with response.cookies.add do
Begin
name:='username';
value:='username';
end
◇[DELPHI] Add to the document menu connection
uses shellapi,shlOBJ;
shAddToRecentDocs(shArd_path,pchar(filepath));//Add connection
shAddToRecentDocs(shArd_path,nil);//Clear
◇[Married Category] Backup Intelligent ABC Input Method Dictionary
windows/system/user.rem
windows/system/tmmr.rem
◇[DELPHI]Judge mouse button
if GetAsyncKeyState(VK_LButton)<>0 then ... //Left key
if GetAsyncKeyState(VK_MButton)<>0 then ... //Medium key
if GetAsyncKeyState(VK_RButton)<>0 then ... //Right-click
◇[DELPHI] Set the maximum display of the form
onformCreate event
self.width:=screen.width;
self.height:=screen.height;
◇[DELPHI] button accepts messages
Handling in the OnCreate event: application.OnMessage:=MyOnMessage;
procedure Tform1.MyOnMessage(var MSG:TMSG;var Handle:Boolean);
Begin
if msg.message=256 then ... //ANY key
if msg.message=112 then ... //F1
if msg.message=113 then ... //F2
end;
◇[Married Category] Hide shared folders
Sharing effect: accessible, but not visible (in resource management, network neighbors)
Take the share name: direction$
Visit://computer/direction/
◇[java Script] Common effects of Java Script web pages
Web pages are closed regularly for 60 seconds
<script language="java script"><!--
settimeout('window.close();',60000)
--></script>
Close the window
<a href="/" onclick="Javascript:window.close();return false;">Close</a>
Timed URL
<meta http-equiv="refresh" content="40;url=http://www.086net.com">
Set as home page
<a onclick="this.style.behavior='url(#default#homepage)'; this.sethomepage('http://086net.com');"href="#">Set as homepage</a>
Bookmark this site
<a href="javascript:window.external.addfavorite('http://086net.com','[Weiming Pier]')">Save this site</a>
Join the channel
<a href="javascript:window.external.addchannel('http://086net.com')">Join the channel</a>
◇[DELPHI] Randomly generate text color
randomize;//Randomize seeds
memo1.font.color:=rgb(random(255),random(255),random(255));
◇[DELPHI]DELPHI5 UPDATE upgrade patch serial number
1000003185
90X25fx0
◇[DELPHI] Illegal character filtering of file names
for i:=1 to length(s) do
if s[i] in ['/','/',':','*','?','<','>','|'] then
◇Definition and description of [DELPHI] conversion function
datetimetofiledate (datetime:Tdatetime):longint; Convert datetime value in Tdatetime format to datetime value in DOS format
datetimetostr (datetime:Tdatetime):string; Convert Tdatatime format variables into strings. If the datetime parameter does not contain date values, the return string date displays as 00/00/00. If there is no time value in the datetime parameter, the return string is returned. The time part of the display is 00:00:00 AM
datetimetostring (var result string;
const format:string;
datetime:Tdatetime); Convert time and date values according to the given format string, result is the result string, format is the conversion format string, and datetime is the datetime value
datetostr (date:Tdatetime) Use the format string defined by shortdateformat global variable to convert the date parameter to the corresponding string
floattodecimal (var result:Tfloatrec;value:
extended;precision,decimals:
integer); convert floating point numbers into decimal representation
floattostr (value:extended):string Converts the floating-point value to a string format. This conversion uses a normal number format, and the number of significant digits converted is 15 bits.
floattotext (buffer:pchar;value:extended;
format:Tfloatformat;precision,
digits:integer):integer; Use the given format, precision and decimal to convert the floating-point value value into a decimal representation. The conversion result is stored in the buffer parameter. The return value of the function is the number of characters stored in the buffer. The buffer is not 0 result string buffer.
floattotextfmt (buffer:pchar;value:extended;
format:pchar):integer converts the floating-point value into a decimal representation in the given format, and the conversion result is stored in the buffer parameter. The function returns the value as the number of characters stored in the buffer.
inttohex (value:longint;digits:integer):
string; Converts the given numeric value to a hexadecimal string. The parameter digits gives the number of digits contained in the conversion result string.
inttostr (value:longint):string Convert integers into decimal strings
strtodate (const S:string):Tdatetime Converts a string to a date value. S must contain a string with a legal format date.
strtodatetime (const S:string):Tdatetime Converts the string S into a date-time format. S must have MM/DD/YY HH:MM:SS[AM|PM] format, where the date and time separators are combined with the system time time constants Settings related. If no AM or PM information is specified, it means that the 24-hour system is used.
strtofloat (const S:string):extended; Converts the given string to a floating point number, and the string has the following format:
[+|-]nnn…[.]nnn…[<+|-><E|e><+|->nnnn]
strtoint (const S:string):longint Converts a numeric string into an integer. The string can be in decimal or hexadecimal format. If the string is not a legal numeric string, an ECONVERTERROR exception occurs in the system.
strtointdef (const S:string;default:
longint):longint; Convert the string S to a number. If S cannot be converted to a number, the strtointdef function returns the value of the parameter default.
strtotime (const S:string):Tdatetime Converts the string S to a TDATETIME value, S has the HH:MM:SS[AM|PM] format, and the actual format is related to the global variables related to the system's time.
timetostr (time:Tdatetime):string; Converts the parameter TIME into a string. The format of the conversion result string is related to the setting of the system's time-dependent constants.
◇[DELPHI] program does not appear in ALT+CTRL+DEL
Add a declaration after implementation:
function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external 'KERNEL32.DLL';
RegisterServiceProcess(GetCurrentProcessID, 1);//Hide
RegisterServiceProcess(GetCurrentProcessID, 0);//Show
Can't see it with ALT+DEL+CTRL
◇[DELPHI] program does not appear in the taskbar
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]How to determine whether dial-up network is on or off
if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then
showmessage('Online!')
else showmessage('not online!');
◇[DELPHI] Implement IP to domain name conversion
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] Method for handling "right-click menu"
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('', 'Action(&C)');
reg.CloseKey;
reg.Free;
showmessage('DONE!');
end;
◇[DELPHI]Send virtual key value 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] The current optical drive's drive letter
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] characters encryption and decryption
function cryptstr(const s:string; type: dword):string;
var
i: integer;
fkey: integer;
Begin
result:='';
case type 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]Send simulation keys to other applications
var
h: THandle;
Begin
h := FindWindow(nil, 'application title');
PostMessage(h, WM_KEYDOWN, VK_F9, 0);//Send F9 key
end;
□◇[DELPHI]DELPHI Supported DAO data format