Delphi programming skills

zhaozj2021-02-11  271

Delphi as a new Windows programming language due to its set

Many excellent features are more and more professionals and

The favor of enthusiasts. The following ten skills involved is relatively wide, hoping

It is beneficial to Delphi's enthusiasts.

1. Similar to VB. DOEvents function.

Everyone may find that there is no similar to VB in Delphi. DOEV

ENTS function, so sometimes we will not respond to Windows

A simultaneous event. In fact, in Delphi Application Object

Including a similar method: ProcessMessage, you can pass

Use Application. ProcessMessage to complete like VB. DOEVE

NTS is the same function.

2. Call NetscapeAvigator in Delphi.

As the Internet is hot, have you ever thought about your Delphi program?

Start the Netscape browser 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ιne

Tscape. 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 more large numbers are not easy to read during output, in Delphi

The number showing the nodes is quite simple, as follows: XX

XXX. Caption: κ millmatfloat ('#', 524667500).

4. Get a prompt at compile.

In Delphi2.0, you can let the compiler tell you some time

Tip, such as which variables are declared, but they have never used it. We know that you can control whether Delphi is going to do through the options in the menu.

But if you need DE as you specify due to some special needs

What should I do with LPHI? 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 wallpapers, please refer to the following

program.

Procedurechangeit;

VAR

REG: TREGINIFILE;

Begin

Κ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-SendwiniChange;

END;

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

There is a new feature in Win95, which is to get access files.

The last date. The famous CleansweapForWin95 software is relying on this

One function is one of the basis for judging whether a file is often accessed.

In Delphi, we can reach this through the following programs.

FunctionGetfilelastic (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, ConvertDostimetdatetimeforusein

Delphi'snativeDate / TimeFunctions

Result: filedatetodatetime (DFT);

END;

END;

GetFilelasticAccesstime () will take Delphi TDateTi

The ME format returns the last accessed date of the file you specified.

7. Colorful labels.

We are not satisfied with the simple label provided by Delphi, can

There are different fonts in the label, there are different colors to enrich us.

Performance. The answer is yes, and does not include the control of the third party

Part, we only need to use the trichedit that delphi yourself.

Yes. First remove the border of the trichedit control: riched -it1

. Borderstyle: κBsnone; simultaneous setting of read-only properties true: Rich

Edit1. Readonly: κtrue; then, you use Write and the like

Software makes text in RichText format, can be displayed by the following statement

Showed:

Richedit1. PlainText: κfalse;

Richedit1. Lines. LoadFromfile ('c: TEST.R

TF ');

8. How to prevent Win95 from displaying serious errors.

No matter how your program repeatedly debugged, after handing over to the user, there is always

How can you happen unexpected mistakes, how to avoid Win95 display over white

The window tells you that the user has an embarrassment error? We can

this way:

VAR

Wolderror mode: word;

Begin

// TellWin-DowstoIgnorecriprRiticalerRorsandsave

CurRenterrorMode

Wolderror-Mode: κseterrorMode (SEM-Failcr)

Iti -calerrors);

Try

// CodetHatmightGenerateAcriticalerrorGoesher

e. . .

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 has played a lot, but due to historical reasons, even in Delphi, it is also in Delphi due to historical reasons.

Not valid enough, the following program can tell you how to know the right mouse

Object name. First create a popmenu, then the following code can be

Tell you the object name just right-click: Popupmenu1. Popuppcom

Ponent. Classname.

10. Detect whether the CD-ROM or other disks has changed.

The simplest method of checking if the CD-ROM or the disk has changed

It is checking its Volume number. You can simply use the following functions to return

Back to disk Volume series number 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;