[DELPHI] Network Neighborhood copy files
Uses SHELLAPI;
CopyFile (Pchar (' Newfile.txt '), Pchar ('//computername/direction/targer.txt '), false);
[DELPHI] produces mouse drag effect
Implemented through MouseMove events, DragOver events, EndDrag events, such as label on a panel:
var Xpanel,ypanel,xlabel,ylabel:integer;
Panel's MouseMove event: xpanel:=x;ypanel:=y;
Panel's DragOver event: xpanel:=x;ypanel:=y;
MouseMove event for label: Xlabel:=x;ylabel:=y;
EndDrag event for label: Label.left:=xpanel-xlabel;label.top:=ypanel-ylabel;
[DELPHI] Get the Windows directory
Uses SHELLAPI;
var windir:array[0..255] of Char;
GetWindowsDirectory (windir,sizeof (windir));
Or read from the registry, location:
Hkey_local_machine/software/microsoft/windows/currentversion
SystemRoot key, obtained such as: 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));
The [DELPHI] string list uses
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 files, directory operations
Chdir (' C:/abcdir '); Go to Directory
Mkdir (' dirname '); Directory creation
Rmdir (' dirname '); Delete directory
getcurrentdir;//to take the current directory name, none '/'
Getdir (0,s)//Take working directory name s:= ' C:/abcdir ';
Deletfile (' abc.txt ');//delete file
RenameFile (' Old.txt ', ' new.txt ')/File name change
Extractfilename (filelistbox1.filename);//FETCH filename
Extractfileext (filelistbox1.filename);//Fetch file suffix
[DELPHI] Processing file properties
Attr:=filegetattr (Filelistbox1.filename);
if (attr and fareadonly) =fareadonly then ...//Read Only
if (attr and Fasysfile) =fasysfile then ...//System
if (attr and faarchive) =faarchive then ...//Archive
if (attr and Fahidden) =fahidden then ...//Hide
[DELPHI] Execute the program outside the file
winexec//Invoke executable file
WinExec (' command.com/c copy *.* c:/', sw_normal);
WinExec (' Start abc.txt ');
ShellExecute or shellexecuteex//Startup 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:tingweb@wx88.net ', ', ', ', ', 0);
[DELPHI] Get 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] on the embedding of the Assembly
ASM end;
Can modify EAX, ECX, EDX arbitrarily, cannot modify ESI, EDI, ESP, EBP, EBX.
[DELPHI] About type conversion functions
floattostr//floating-point spin string
floattostrf//-formatted floating-point spin string
inttohex//Integer Turn 16
Timetostr
Datetostr
Datetimetostr
fmtstr//output string in specified format
FormatDateTime (' Yyyy-mm-dd,hh-mm-ss ', DATE);
procedures and functions of the [DELPHI] string
Insert (Obj,target,pos);//string target is inserted at the position of the Pos. If the insertion result is greater than the target maximum length, the extra characters will be truncated. If the POS is outside 255, it will generate a run-time error. For example, st:= ' Brian ', then insert (' OK ', st,2) will make St ' Brokian '.
Delete a substring of Num (integer) characters from the POS (integer) position in the St string (st,pos,num). For example, st:= ' Brian ', then delete (st,3,2) will become BRN.
STR (value,st);//converts numeric value (integer or solid) to a string in St. For example, when A=2.5e4, str (a:10,st) will make St's value ' 25000 '.
Val (St,var,code)//Converts the string expression st to the corresponding integer or real value, stored in var. St must be a string representing the numeric value and conform to the rules for numeric constants. In the conversion process, if no error is detected, the variable code is set to 0, otherwise it is positioned as the first out of the character. For example, St:=25.4e3,x is a real variable, and Val (st,x,code) causes the X value to be a 25400,code value of 0.
Copy (St.pos.num); Returns a substring of the num (integer) character at the beginning of POS (integer) in a position in the St string. If the POS is larger than the length of the St string, it returns an empty string, which causes a run error if the POS is outside 255. For example, st:= ' Brian ', then copy (st,2,2) returns ' Ri '.
Concat (ST1,ST2,ST3......,STN);//The strings represented by all the arguments are concatenated in the order given, and the concatenated values are returned. If the result is 255 in length, a run-time error is generated. For example, st1:= ' Brian ', st2:= ', st3:= ' Wilfred ', then concat (ST1,ST2,ST3) returns to ' Brian Wilfred '.
Length (ST);//Returns the lengths of the string expression St. For example, st:= ' Brian ', the length (ST) return value is 5.
POS (obj,target); Returns the position in which the string obj first appears in the target string, and if Target does not have a matching string, the return value of the POS function is 0. For example, target:= ' Brian Wilfred ', the return value of the Pos (' Wil ', target) is the return value of 7,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 name
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 (--$5A) (90)
0-9:$30 (48)--$39 (57)
[DELPHI] Preliminary judgment procedure mother tongue
Delphi Software DOS prompt: This program must is Run Under Win32.
VC + + software DOS prompt: This program cannot is Run in DOS Mode.
◇[delphi] Manipulating cookies
Response.Cookies ("name"). domain:= ' http://www.086net.com ';
With Response.Cookies.Add do
Begin
name:= ' username ';
value:= ' username ';
End
◇[delphi] Added to the document menu connection
Uses shellapi,shlobj;
Shaddtorecentdocs (Shard_path,pchar (filepath));//Increase connection
Shaddtorecentdocs (Shard_path,nil);/empty
[DELPHI] To judge the mouse button
If Getasynckeystate (Vk_lbutton) <>0 then ...//left
If Getasynckeystate (Vk_mbutton) <>0 then ...//Middle key
If Getasynckeystate (Vk_rbutton) <>0 then ...//Right button
[DELPHI] Set the maximum display of a form
Onformcreate Events
Self.width:=screen.width;
Self.height:=screen.height;
[DELPHI] Press the key to accept the message
OnCreate event Processing: 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
[DELPHI] Gets the RGB value of a point on the image
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] About date format decomposition conversion
var year,month,day:word;now2:tdatatime;
Now2:=date ();
Decodedate (Now2,year,month,day);
Lable1. Text: =inttostr (year) + ' +inttostr ' (month) + ' month ' +inttostr (day) + ' th ';
[DELPHI] How to determine the current network connection mode
The result is modem, local area network or proxy server.
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] How to determine whether a string is a valid email address
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] Determines whether the system is connected to the Internet
The Inetisoffline function in URL.DLL needs to be introduced.
Function declared as:
function Inetisoffline (Flag:integer): Boolean; stdcall; External ' URL. DLL ';
Then you can call the function to determine if the system is connected to the Internet
If Inetisoffline (0) then ShowMessage (' Not connected! ')
else ShowMessage (' connected! ');
This function returns True if the local system is not connected to the Internet.
Report:
Most systems equipped with IE or OFFICE97 have this DLL available for invocation.
Inetisoffline
BOOL Inetisoffline (
DWORD dwflags,
);
[DELPHI] simply play and pause wav files
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] Take machine BIOS information
With Memo1.lines do
Begin
Add (' Mainboardbiosname: ' +^i+string (Pchar (PTR ($FE 061)));
Add (' Mainboardbioscopyright: ' +^i+string (Pchar (Ptr ($FE 091)));
Add (' Mainboardbiosdate: ' +^i+string (Pchar (PTR ($FFFF 5)));
Add (' Mainboardbiosserialno: ' +^i+string (Pchar (PTR ($FEC 71)));
End
[DELPHI] Network download files
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] Resolve server IP Address
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] Gets the connection in the shortcut
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 > then
result:= Strpas (exename)
Else
result:= ';
Strdispose (Fdir);
Strdispose (FName);
Strdispose (exename);
End;