As a new Windows programming language, Delphi has
Many excellent features are integrated into one, so it is more and more popular among programmers and programmers.
Favored by audiophiles. The following ten techniques cover a wide range of areas. I hope they can
Enough to be of benefit to Delphi enthusiasts.
1. Similar to vb. doevents function in.
You may find that there is no equivalent to vb. in Delphi. doev in
ents function, so sometimes we won't be able to make Windows respond much
simultaneous events. Actually, in Delphi application object
Includes a similar method: PRocessMessage, you can call
Use application. ProcessMessage to complete like vb. doeve in
nts same function.
2. Call NetscapeNavigator in Delphi.
With the popularity of the Internet, have you ever thought about using it in your Delphi program?
Start the Netscape browser in and display the home page of the WWW address you specified.
. The following program can accomplish this function.
programNetscape;
usesDDEMan;
procedureGo??toURL(sURL: string);
var
dde:TDDEClientConv;
begin
dde: ΚTDDEClientConv. Create(nil);
withddedo
begin
//specifythelocationofnetscape. exe
ServiceApplication: Κ′c: ιns32ιprogramιne
tscape. exe′;
//activatetheNetscapeNavigator
SetLink('Netscape', 'WWW-Activate');
RequestData(′0xFFFFFFFF′);
//gotothespecifiedURL
SetLink('Netscape', 'WWW-OpenURL');
RequestData(sURL+′,,0xFFFFFFFF,0x3,,,
′);
CloseLink;
end;
dde. Free;
end;
begin
GotoURL(′http://www.yahoo.com/′);
end.
3. Formatted integer output.
Larger numbers will appear difficult to read when output, in Delphi
Displaying numbers with section marks is a fairly simple matter, as follows: xx
xxx. caption: ΚFormatFloat(′#′, 524667500).
4. Get hints at compile time.
In Delphi2.0, when compiling, you can ask the compiler to tell you some
Tips, such as which variables are declared but never used. we know
Yes, you can control whether you want Delphi to do this through the options in the menu.
But if due to some special needs, you only need it in the specified code segment.
What should I do if I get a prompt like lphi? Please refer to the following procedures.
{$HINTON}
procedureTform1. Button1Click(Sender: TObject
);
var
X: integer;
begin
end;
{$HINTOFF}
5. Change Windows95 wallpaper.
You can change the wallpaper easily in Delphi, please refer to the following
program.
procedureChangeIt;
var
Reg:TregIniFile;
begin
Reg:ΚTRegIniFile. Create('ControlPanel')
;
Reg. WriteString('desktop', 'Wallpaper',
′c: ιpwin95ιfor??est. bmp′);
Reg. WriteString('desktop', 'TileWallpaper
′,′1′);
Reg. Free;
SystemParametersInfo(SPI-SETDESKWALLPAPER, 0
, nil, SPIF-SENDWININICHANGE);
end;
6. Get the date the file was last used.
There is a new feature in Win95, which is to gain access to files
last date. The famous CleanSweapforWin95 software relies on this
This function is used as one of the basis for judging whether a file is frequently accessed.
In Delphi, we can achieve this function through the following program.
functionGetFileLastaccessTime(sFileName:stri
ng):TDate??Time;
var
ffd:TWin32FindData;
dft:DWord;
lft:TFileTime;
h: THandle;
begin
//getfileinformation
h:ΚWindows. FindFirstFile(PChar(sFileName
), ffd);
if(INVALID―HANDLE―VALUEΙΛ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: ΚFileDateToDateTime(dft);
end;
end;
GetFileLastAccessTime() will use Delphi's TdateTi
me format returns the last access date of the file you specify.
7. Colorful labels.
We are no longer satisfied with the simple tags provided by Delphi. Can we
There are different fonts and different colors in the labels to enrich us
performance ability. The answer is yes, and there is no need for control provided by a third party
software, we just need to cleverly use TRichEdit provided by Delphi itself
That's it. First remove the border of the TRichEdit control: RichEd??it1
. BorderStyle: ΚbsNone; also set the read-only attribute to true: Rich
Ed??it1. ReadOnly: ΚTrue; then, you use write or the like
After the software creates text in RichText format, you can display it through the following statement
It is shown:
RichEdit1. PlainText:ΚFalse;
RichEdit1. Lines. LoadFromFile(′c: ιtest.r
tf′);
8. How to prevent Win95 from displaying critical errors.
No matter how many times you debug your program, after it is handed over to the user, there will always be
Unexpected errors may occur. How to prevent Win95 from displaying white
What about windows that tell your users that an embarrassing, unexpected error has occurred? we can
Do this:
var
wOldError??Mode: Word;
begin
//tellwin??dowstoignorecriticalerrorsandsave
cur??renterrormode
wOldError??Mode: ΚSetEr??rorMode (SEM-FAILCR
ITI??CALERRORS);
try
//codethatmightgenerateacriticalerrorgoesher
e. . .
finally
//gobacktopreviouserrormode
SetErrorMode(wOldErrorMode);
end;
end;
Mainly use SetErrorMode() to complete this function.
9. Which object was just clicked with the mouse.
In Win95, the right button of the mouse plays a big role, but
Due to historical reasons, the use of right-click is still difficult even in Delphi.
Not effective enough, the following program can tell you how to know when you just right-clicked
object name. First create a popmenu, and then the following code can
To tell you the name of the object you just right-clicked: Popup??Menu1. PopupCom
ponent. ClassName.
10. Check whether the CD-ROM or other disks have been changed.
The simplest way to check whether a CD-ROM or disk has been changed
is to check its volume number. You can simply use the following function to return
Return the volume series number of the disk GetDiskVolSerialID ('E'),
The function code is as follows:
functionGetDiskVolSerialID(cDriveName: char)
:DWord;
var
dwTemp1, dwTemp2: DWord;
begin
GetVolumeInformation(PChar(cDriveName+′:
ι′),
Nil,
0,
ΝResult,
dwTemp2,
dwTemp2,
Nil,
0);
end;