As a new windows programming language, Delphi
A large number of excellent features in one, so more and more programmers and
Enthusiasts are favored. The following 10 tips are widely used.
It is beneficial to Delphi fans.
1. Similar to the doevents function in VB.
You may find that in Delphi, there is no doev similar to that in VB.
The Ents function, so sometimes we cannot make windows respond more
Events that occur simultaneously. In fact, the application object in Delphi
This includes a similar method: processmessage. You can call
Use application. processmessage to complete doeve like VB.
The same functions as the default.
2. Call netscapenavigator in Delphi.
With the popularity of the Internet, have you ever thought about your Delphi program?
Start the Netscape Browser to display the home page of your specified WWW address
. The following program can complete this function.
Programnetscape;
Usesddeman;
Proceduregotourl (Surl: string );
VaR
DDE: tddeclientconv;
Begin
DDE: Required tddeclientconv. Create (NiL );
Withddedo
Begin
// Specifythelocationofnetscape.exe
Serviceapplication: Κ 'C: Invalid ns32 Program program runner ne
Tscape.exe ′;
// Activatethenetscapenavigator
Setlink ('netscape ',' www-activate ′);
Requestdata ('0xffffffff ′);
// Gotothespecifiedurl
Setlink ('netscape ',' www-openurl ′);
Requestdata (Surl + ', 0 xffffffff, 0x3 ,,,
′);
Closelink;
End;
DDE. Free;
End;
Begin
Gotourl ('http://www.yahoo.com /′);
End.
3. format the integer output.
A relatively large number is hard to read in the output. in Delphi
It is quite simple to display the number with the shard number, as shown below: xx
Xxx. Caption: Define formatfloat ('#', 524667500 ).
4. Get the prompt during compilation.
In delphi2.0, the compiler can tell you something during compilation.
Tips, such as which variables are declared, but never used. We know
You can use the options in the menu to control whether or not you want Delphi to do so,
However, for some special needs, you only need
What should I do with a prompt like lphi? See the following program.
{$ Hinton}
Proceduretform1.button1click (Sender: tobject
);
VaR
X: integer;
Begin
End;
{$ Hintoff}
5. Change the wallpaper of Windows 95.
You can easily change the wallpaper in Delphi. refer to the following
Program.
Procedurechangeit;
VaR
Reg: treginifile;
Begin
Reg: Required treginifile. Create ('controlpanel ′)
;
Reg. writestring ('desktop ', 'wallpaper ′,
'C: paipwin95425forest.bmp ′);
Reg. writestring ('desktop ', 'tilewallpaper
',' 1 ′);
Reg. Free;
Systemparametersinfo (SPI-SETDESKWALLPAPER, 0
, Nil, SPIF-SENDWININICHANGE );
End;
6. Get the date of the last file used.
A new function in Win95 is to obtain access files.
. The famous cleansweapforwin95 software relies on this
One function is used to determine whether a file is frequently accessed.
In Delphi, we can use the following program to achieve this function.
Functiongetfilelastaccesstime (sfilename: Stri
NG): tdatetime;
VaR
FFD: twin32finddata;
DFT: DWORD;
LFT: tfiletime;
H: thandle;
Begin
// Getfileinformation
H: customized windows. findfirstfile (pchar (sfilename
), FFD );
If (invalid-handle-value then Lambda h) then
Begin
// We 'relookingforjustonefile, socloseour "F
IND ″
Windows. findclose (h );
// Convertthefiletimetolocalfiletime
Filetimetolocalfiletime (FfD. ftlastaccesstime
, LFT );
// Convertfiletimetodostime
Filetimetodosdatetime (LFT, longrec (DFT). Hi
, Longrec (DFT). Lo );
// Finally, convertdostimetotdatetimeforusein
Delphi 'snativedate/timefunctions
Result: required filedatetodatetime (DFT );
End;
End;
Getfilelastaccesstime () will use the tdateti of Delphi
The ME format returns the last access date of the specified file.
7. rich and colorful labels.
We are not satisfied with the simple tag provided by Delphi. Can we?
The labels have different fonts and colors to enrich us.
Performance. The answer is yes, and no third-party control is required.
As long as we cleverly use the trichedit provided by Delphi
Yes. First, remove the border of the trichedit control: richedit1
. Borderstyle: Repeated bsnone; set the read-only attribute to true: rich
Edit1.readonly: Required true; then, you use the write
The software has prepared the richtext text format, and the following statement can be used to display
Shown below:
Richedit1.plaintext: Invalid false;
Richedit1.lines. loadfromfile ('C: Your test. r
Tf ′);
8. How to Prevent Win95 from displaying serious errors.
No matter how your program is debugged repeatedly, it will always work after it is handed over to the user.
How can we avoid white display in Win95 when unexpected errors occur?
Window, tell your user what happened to an embarrassing Unexpected error? We can
In this way:
VaR
Wolderrormode: word;
Begin
// Tellwindowstoignorecriticalerrorsandsave
Currenterrormode
Wolderrormode: eclipseterrormode (SEM-FAILCR
Iticalerrors );
Try
// Codethatmightgenerateacriticalerrorgoesher
E...
Finally
// Gobacktopreviuserrormode
Seterrormode (wolderrormode );
End;
End;
This function is mainly implemented using seterrormode.
9. Which object was clicked with the mouse just now.
IN Win95, right-clicking has played a major role. However,
Due to historical reasons, the right-click is used even in Delphi.
The following program shows you how to right-click the mouse
Object Name. First create a popmenu, and then the following code can be
To tell you the name of the right-click object: popupmenu1.popupcom
Ponent. classname.
10. Check if the CD-ROM or other disks have changed.
The easiest way to check for changes to the CD-ROM or disk
Is to check its volume number. You can simply use the following functions to return
Back to the disk's volume series number getdiskvolserialid ('E ′),
The function code is as follows:
Functiongetdiskvolserialid (cdrivename: Char)
: DWORD;
VaR
Dwtemp1, dwtemp2: DWORD;
Begin
Getvolumeinformation (pchar (cdrivename + ′:
Comment ′),
Nil,
0,
Else result,
Dwtemp2,
Dwtemp2,
Nil,
0 );
End;