Delphi programming skill instance

zhaozj2021-02-17  55

Delphi Programming Skills Example Ni Tian Delphi as a new Windows programming language, because of the many outstanding features, it is increasingly favored by the majority of programmers and enthusiasts. The following ten techniques involved is relatively wide, hoping to benefit Delphi's enthusiasts.

1. Similar to VB. DOEvents function.

Everyone may find that there is no similar to VB in Delphi. The doevents function in this time, we will not allow Windows to respond to multiple simultaneous events. In fact, a similar approach is included in the Application object in Delphi: ProcessMessage, you can call Application. ProcessMessage to complete like VB. The same functionality is the same as the DOEvents.

2. Call NetscapeAvigator in Delphi.

As the Internet is hot, have you ever thought about launching the Netscape browser in your Delphi program to display the homepage of the WWW address you specify. The following program can complete this feature.

Programnetscape;

Usesddeman;

Procedurego-Tourl (SURL: String);

VAR

DDE: TDDECLIENTCONV;

Begin

DDE: = TDDECLIENTCONV. Create (nil);

Withddo

Begin

// SpecifyThelocationOfnetScape. EXE

ServiceApplication: = 'C: / NS32 / Program / Netscape. EXE ';

// ActivateThenetscapeAvigator

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. Format integer output.

The relatively large number is not easy to read when the output is output, and the number that is displayed in Delphi is quite simple, as follows: xxxxx. Caption: κ millmatfloat ('#', 524667500).

4. Get a prompt at compile.

In Delphi 2.0, when compiling, you can let the compiler tell you some prompts, such as which variables are declared, but never used. We know that you can control whether you want delphi in the options in the menu, but if you need a tips like Delphi in the specified code segment, what should I do? Please refer to the following program. {$ Hinton}

Proceduretform1. Button1Click (Sender: TOBJECT);

VAR

X: integer;

Begin

END;

{$ Hintoff}

5. Change wallpaper of Windows95.

In Delphi, you can easily change the wallpaper, please refer to the following programs.

Procedurechangeit;

VAR

REG: TREGINIFILE;

Begin

Κtreginifile. CREATE ('ControlPanel');

REG. WriteString ('Desktop', 'Wallpaper', 'C: /PWIN95/Forest.bmp ");

REG. WriteString ('Desktop', 'TileWallpaper', '1');

REG. FREE;

SystemParametersInfo (Spi-setDeskwallpaper, 0, nil, spif-sendwiniInichange);

END;

6. Get the date of the last use of the file.

There is a new feature in Win95, which is to get the last date of the access file. The famous CleansWeapForWin95 software is one of the basis for judging whether a file is often accessed. In Delphi, we can reach this through the following programs.

FunctiongetFileLastAccesstime (sfilename: string): 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 "Find"

WINDOWS. FindClose (h);

// convertthefiletimetolocalfiletime

FileTimetolocalFileTime (ffd.ftlastaccesstime, LFT); // converTfileTimetodostime

FiletimetodosDatetime (LFT, Longrec (DFT) .hi, LongRec (DFT) .lo);

// finally, convertdostimetdatetimeforuseindelphi'snativedate / timefunctions

Result: filedatetodatetime (DFT);

END;

END;

GetFileLastAccesstime () will return the last accessed date of the file you specified in the TDATETIME format of Delphi.

7. Colorful labels.

We are not satisfied with the simple label provided by Delphi, you can't have different fonts in the label, have different colors to enrich our performance. The answer is affirmative, and uses the controls provided by third parties, we can use the trichedit they provide with Delphi. First remove the border of the trichedit control: richedit1. Borderstyle: κBsnone; simultaneous setting of read-only properties is true: richedit1. Readonly: κtrue; then, you can use the software such as Write to make text, you can display it through the following statement:

Richedit1. PlainText: κfalse;

Richedit1. Lines. LoadFromfile ('c: /test.rtf');

8. How to prevent Win95 from displaying serious errors.

No matter how your programs have repeatedly commissioned, after handing over to the user, there may always happen unexpected errors, how to avoid Win95 display a white window, telling your users to have a embarrassing accident error? We can do this:

VAR

Wolderror mode: word;

Begin

// Tellwin-DowstoIgnorecriticalerRorsandsavecur rrenterrorMode

Wolderror-Mode: SETER RORMODE (SEM-Failcriti-Calerrror);

Try

// CodetHatmightGenerateAcriticalerrorGoeshere. . .

Finally

// gobacktopreviouserrormode

SETERRORMODE (WolderRormode);

END;

END;

It is mainly to use setErrorMode () to complete this feature.

9. Which object is just hit using a mouse.

In Win95, the right button of the mouse played a lot, but due to historical reasons, even in Delphi, the following programs can tell you how to know the name of the object that just right . First create a popmenu, then the following code can tell you the object name just right-click: Popupmenu1. PopupComponent. Classname. 10. Detect whether the CD-ROM or other disks has changed.

The simplest method for checking if the CD-ROM or whether there is a change in the disk is to check its Volume number. You can simply use the following functions to return to the Volume Series Number GetDiskVolSeriAlId ('E') of the disk, 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;

转载请注明原文地址:https://www.9cbs.com/read-29612.html

New Post(0)