Delphi Basic Development Skills (i)

Source: Internet
Author: User
Tags valid email address

Delphi Basic Development Skills
◇[delphi] Network Neighbors copy files
Uses SHELLAPI;
CopyFile (Pchar (' Newfile.txt '), Pchar ('//computername/direction/targer.txt '), false);
◇[delphi] produces a 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 a line on a form or other container
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 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 an out-of-process 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] Gets 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] about 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);
◇[delphi] string procedures and functions
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 handling 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)
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
◇[Miscellaneous] Backup Intelligent ABC input Word Library
Windows/system/user.rem
Windows/system/tmmr.rem
◇[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
◇[Miscellaneous] Hide Shared folders
Shared effects: accessible, but not visible (in resource management, Network Neighborhood)
Take the share name: direction$
Visit://computer/dirction/
◇[java Script]java Script Web page Common effects
Web page 60 seconds off

Close window
Shut down
Timed forwarding URL
Data source, one is MQIS, one is localsever, choose a SELECT after click Configure button, do not know your SQL7.0
is not installed on the local machine, if it is to proceed directly to the next step, if not, in the server column to fill in
Server, and then proceed to the next step, fill in the login ID and password (login ID, and password is the user option in SQL7.0)
).
The second step is to configure BDE:
Open the Delphi BDE, then click MQIS or LocalServer, will prompt user name and password, this and
ODBC user name and password is the same, fill in on the line.
The third step is to configure the program:
If you are using Ttable, select MQIS or LocalServer in the databasename of ttable, and then
TableName Select sale on the line, and then change the active to True,delphi pop-up prompt dialog, fill in the user
Name and password.
If you are using Tquery, right-click on the Tquery and click "SQL Builder", which is configured as an interface
SQL statements, or populate SQL statements in Tquery SQL. Finally, don't forget to change the active to true.
In the run may also configure Tquery, specifically see Delphi Help.
-◇[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 conversions
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] Determine if 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] resolves server IP addresses
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] Get 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
◇[delphi] Controls automatic completion of Tcombobox
{' Sorted ' of the Tcombobox to True}
var Lastkey:word; Global variables
The onchange event of Tcombobox
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
The onkeydown event of Tcombobox
Procedure Tform1.autocompletekeydown (Sender:tobject; var Key:word;
Shift:tshiftstate);
Begin
Lastkey: = Key;
End
◇[delphi] How to empty a directory
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
To be continued/////////////////////////////////////////// ////

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.