0% found this document useful (0 votes)
498 views

Hide A Delphi Application Button From The Taskbar: Capture Desktop Image Into A Tbitmap Object

The document provides code snippets for common tasks in Delphi applications, such as: 1) Hiding a Delphi application button from the Windows taskbar by setting the application window as a tool window. 2) Capturing a screenshot of the desktop and displaying it in an image control by getting the desktop window handle and bitmap dimensions. 3) Changing the font properties of tooltips by overriding the hint window constructor and setting the canvas font.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
498 views

Hide A Delphi Application Button From The Taskbar: Capture Desktop Image Into A Tbitmap Object

The document provides code snippets for common tasks in Delphi applications, such as: 1) Hiding a Delphi application button from the Windows taskbar by setting the application window as a tool window. 2) Capturing a screenshot of the desktop and displaying it in an image control by getting the desktop window handle and bitmap dimensions. 3) Changing the font properties of tooltips by overriding the hint window constructor and setting the canvas font.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 104

Hide a Delphi Application Button from the TaskBar

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he "utton on the #indows !ask$ar, %or a Delphi application, "elongs to the &pplication window, the hidden window maintained "' the &pplication o"ject, not the main %orm window. !o hide your Delphi application (button) from the TaskBar 'ou need to change some speci%ic attri"utes o% the &pplication window. (ere)s how... *n order to hide the "utton on the !ask$ar 'ou need to use the Set#indow+ong &P* %unction that changes an attri"ute o% the speci%ied window. $' appl'ing #S,-.,!//+#*ND/# %or the G#+,-.S!Y+- 'ou mark the application window as a tool"ar window. & tool window does not appear in the task"ar or in the dialog "o0 that appears when the user presses &+!1!&$. !o remo2e the %licker when calling the Set#indow+ong, 'ou %irst hide the window then show it again using Show#indow with parameters S#,(*D- and S#,S(/#. !he code "elow is a handler %or the !3ainForm)s /n4reate e2ent. Presuma"l', 5!3ainForm5 is the main %orm o% 'our application. procedure !3ainForm.Form4reate6Sender7 !/"ject8 9 begin Show#indow6&pplication.(andle, S#,(*D-8 9 Set#indow+ong6&pplication.(andle, G#+,-.S!Y+-, get#indow+ong6&pplication.(andle, G#+,-.S!Y+-8 or #S,-.,!//+#*ND/#8 9 Show#indow6&pplication.(andle, S#,S(/#8 9 end9

Desktop creen hot using Delphi !ode


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

!apture Desktop "mage into a TBitmap ob#ect

Need to take a #indows Desktop screen shoot %rom Delphi code: No pro"lem ... here)s how to capture the #indows Desktop image into a !$itmap o"ject ; and displa' it inside a !*mage control. Drop a !*mage 6named 5*mage<58 on a %orm and use the %ollowing code7 procedure ScreenShot6Dest$itmap 7 !$itmap8 9 $ar D4 7 (D49 begin D4 7= GetD4 6GetDesktop#indow8 9 try Dest$itmap.#idth 7= GetDe2ice4aps 6D4, (/>Z>-S8 9 Dest$itmap.(eight 7= GetDe2ice4aps 6D4, ?->!>-S8 9 $it$lt6Dest$itmap.4an2as.(andle, @, @, Dest$itmap.#idth, Dest$itmap.(eight, D4, @, @, S>44/PY8 9 finally >eleaseD4 6GetDesktop#indow, D48 9 end9 end9 Note7 the width and height o% the screen shot are eAual to the width and height o% the ph'sical screen. Usage7 $ar "7!$itmap9 begin " 7= !$itmap.4reate9 try ScreenShot6"8 9 *mage<.Picture.$itmap.&ssign6"8 9 finally ".Free*mage9 Free&ndNil6"8 9 end9

ToolTip font hint properties


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to change the %ont in !ool!ip propert' o% Delphi controls 6(int "o08 7 BBBBBBBBBBBBBBBBBBBBBBBBB !'pe

!3'(int#indow = 4lass 6!(int#indow8 4onstructor 4reate 6&/wner7 !4omponent8 9 o2erride 9 end9 4onstructor !3'(int#indow.4reate6&/wner7!4omponent8 9 "egin *nherited 4reate 6&/wner8 9 4an2as.Font.Name 7= )4ourier New) 9 4an2as.Font.SiCe 7= DE9 end9 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin &pplication.Show(int 7= %alse9 (int#indow4lass 7= !3'(int#indow9 &pplication.Show(int 7= !rue9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Date%Time and other "nternational settings


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now $' de%ault, Delphi gets its dateFtime, currenc' and numeric %ormat %rom 4ontrol Panel)s *nternational settings. #e can set the constants de%ined in Delphi, like DecimalSeparator, ShortDateFormat and others like in the code "elow. !o a complete list o% these 2aria"les, look at 4urrenc' and dateFtime %ormatting 2aria"les in Delphi (elp. BBBBBBBBBBBBBBBBBBBBBBBBB procedure Set+ocale9 "egin DecimalSeparator 7= ).)9 !housandSeparator 7 = ),)9 ShortDateFormat 7= )mmFddF'')9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

&indo' flashing
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Flashing a window means changing the appearance o% its caption "ar as i% the window were changing %rom inacti2e to acti2e status, or 2ice 2ersa.

!'picall', a window is %lashed to in%orm the user that the window reAuires attention "ut that it does not currentl' ha2e the ke'"oard %ocus. !he Flash#indow &P* %unction %lashes the window onl' once. !o create a %lashing window add a !!imer component on a %orm, and use the %ollowing code in the /n!imer e2ent handler7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.!imer<!imer6Sender7 !/"ject8 9 "egin Flash#indow 6(andle, !rue8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

(pen ) !lose !D*dri$e from code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now >emem"er to include the 33S'stem unit in 'our uses clause... BBBBBBBBBBBBBBBBBBBBBBBBB G !o /P-N the 4D;>/37 H mciSendString 6)Set cdaudio door open wait), nil, @, handle8 9 G !o 4+/S- the 4D;>/37 H mciSendString 6)Set cdaudio door closed wait), nil, @, handle8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

Delete folders recursi$ely


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing %unction completel' deletes a director' regardless o% whether the director' is %illed or has su"directories. No con%irmation is reAuested so "e care%ul. *% the operation is success%ul then !rue is returned, False otherwise. Usage i% Del!ree6)c7I!empDir)8 then Show3essage6)Director' deleted )8 else Show3essage6)-rrors occured )8 9

BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&P*9 Function Del!ree6DirName 7 string87 $oolean9 2ar S(File/pStruct 7 !S(File/pStruct9 Dir$u% 7 arra' [email protected] o% char9 "egin tr' Fillchar6S(File/pStruct,SiCeo%6S(File/pStruct8,@8 9 Fill4har6Dir$u%, SiCeo%6Dir$u%8, @ 8 9 StrP4op'6Dir$u%, DirName8 9 with S(File/pStruct do "egin #nd 7= @9 pFrom 7= MDir$u%9 wFunc 7= F/,D-+-!-9 %Flags 7= F/F,&++/#UND/9 %Flags 7= %Flags or F/F,N/4/NF*>3&!*/N9 %Flags 7= %Flags or F/F,S*+-N!9 end9 >esult 7= 6S(File/peration6S(File/pStruct8 = @8 9 e0cept >esult 7= False9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et File ,-ast .odified, attribute


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Usage7 la"el<.4aption7=File+ast3odi%ied6)c7Iautoe0ec."at)8 9 BBBBBBBBBBBBBBBBBBBBBBBBB %unction File+ast3odi%ied 6const !heFile7 string87 string9 2ar File( 7 !(andle9 +ocalF! 7 !File!ime9 DosF! 7 D#/>D9 +ast&ccessed!ime 7 !Date!ime9 FindData 7 !#inNEFindData9 "egin >esult 7= ))9 File( 7= FindFirstFile6P4har6!heFile8, FindData8 9 i% File( OP *N?&+*D,(&ND+-,?&+U- then "egin #indows.Find4lose6(andle8 9 i% 6FindData.dwFile&ttri"utes &ND F*+-,&!!>*$U!-,D*>-4!/>Y8 = @ then

"egin File!ime!o+ocalFile!ime 6FindData.%t+ast#rite!ime,+ocalF!8 9 File!ime!oDosDate!ime 6+ocalF!,+ong>ec6DosF!8.(i,+ong>ec6DosF!8.+o8 9 +ast&ccessed!ime 7= FileDate!oDate!ime6DosF!8 9 >esult 7= Date!ime!oStr6+ast&ccessed!ime8 9 end9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Reading a directory content


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing e0ample lists all %iles and su"directories o% the 47I#indows director' into a !+ist$o0 called +ist$o0<7 Find&ll6)47I#indowsIQ.Q),%a&n'File,+ist$o0<.*tems8 BBBBBBBBBBBBBBBBBBBBBBBBB procedure Find&ll 6const Path7 String9 &ttr7 *nteger9 +ist7 !Strings8 9 2ar >es7 !Search>ec9 -/Found7 $oolean9 "egin -/Found7= False9 i% FindFirst6Path, &ttr, >es8 O @ then e0it else while not -/Found do "egin +ist.&dd6>es.Name8 9 -/Found7= FindNe0t6>es8 OP @9 end9 Find4lose6>es8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-eft/ .id/ Right tring


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

. +e%tStr68 takes a certain portion o% the le%t side o% a string. . 3idStr68 takes a speci%ied num"er o% characters %rom a string. . >ightStr68 takes a certain portion o% the right side o% a string. +et)s sa' we ha2e a string Dstr 7= )Delphi is the $-S!), then +e%tStr6Dstr, K8 7= )Delph) 3idStr6Dstr, R, D8 7= )i is th) >ightStr6Dstr, R8 7= )e $-S!) BBBBBBBBBBBBBBBBBBBBBBBBB %unction >ightStr 64onst Str7 String9 SiCe7 #ord87 String9 "egin i% SiCe P +ength6Str8 then SiCe 7= +ength6Str8 9 >ightStr 7= 4op'6Str, +ength6Str8;SiCe1<, SiCe8 end9 %unction 3idStr 64onst Str7 String9 From, SiCe7 #ord87 String9 "egin 3idStr 7= 4op'6Str, From, SiCe8 end9 %unction +e%tStr 64onst Str7 String9 SiCe7 #ord87 String9 "egin +e%tStr 7= 4op'6Str, <, SiCe8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB p.s. /r, i% 'ou ha2e Delphi R1, 'ou an use the +e%tStr, >ightStr or the 4op' >!+ %unctions.

Re$erse a tring
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his %unction returns a string whose 2alues are all re2ersed. !he %irst character is last and the last is %irst. +et)s sa' 'ou ha2e a string )testing string re2erse) than String,re2erse would result in )esre2er gnirts gnitset). BBBBBBBBBBBBBBBBBBBBBBBBB Function String,>e2erse6S 7 String87 String9 ?ar i 7 *nteger9 $egin

>esult 7= ))9 For i 7= +ength6S8 Down!o < Do $egin >esult 7= >esult 1 4op'6S,i,<8 9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB p.s. /r, i% 'ou ha2e Delphi R1, 'ou an use the >e2erseString >!+ %unction.

earch And Replace


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now +et)s sa' 'ou ha2e a string )testing9search9and9replace) and 'ou want to replace )9) with spaces. (ere)s how 'ou)d call this %unction7 s/ldString7=)testing9search9and9replace)9 sNewString7=Search&nd>eplace6s/ldString, )9), ) )8 BBBBBBBBBBBBBBBBBBBBBBBBB %unction Search&nd>eplace 6sSrc, s+ookFor, s>eplace#ith 7 string8 7 string9 2ar nPos, n+en+ookFor 7 integer9 "egin nPos 7= Pos6s+ookFor, sSrc8 9 n+en+ookFor 7= +ength6s+ookFor8 9 while 6nPos P @8 do "egin Delete6sSrc, nPos, n+en+ookFor8 9 *nsert6s>eplace#ith, sSrc, nPos8 9 nPos 7= Pos6s+ookFor, sSrc8 9 end9 >esult 7= sSrc9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB p.s. /r, i% 'ou ha2e Delphi R1, 'ou an use the String>eplace >!+ %unction.

Rotating Te0t
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere is an e0ample o% te0t output that is rotated SK degrees7

BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar l% 7 !+ogFont9 t% 7 !Font9 "egin with Form<.4an2as do "egin Font.Name 7= )&rial)9 Font.SiCe 7= ES9 t% 7= !Font.4reate9 tr' t%.&ssign6Font8 9 Get/"ject6t%.(andle, siCeo%6l%8, Ml%8 9 l%.l%-scapement 7= SK@9 l%.l%/rientation 7= SK@9 t%.(andle 7= 4reateFont*ndirect6l%8 9 Font.&ssign6t%8 9 %inall' t%.Free9 end9 !e0t/ut6E@, (eight di2 E, )>otated !e0t )8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!hecking "f File "s "n 1se


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *sFile*nUse will return true i% the %ile is locked %or e0clusi2e access. *t would %ail i% the %ile doesn)t e0ist at all. BBBBBBBBBBBBBBBBBBBBBBBBB %unction *sFile*nUse6%Name 7 string8 7 "oolean9 2ar (File>es 7 (F*+-9 "egin >esult 7= %alse9 i% not File-0ists6%Name8 then e0it9 (File>es 7= 4reateFile6pchar6%Name8, G-N->*4,>-&D or G-N->*4,#>*!-, @, nil, /P-N,-.*S!*NG, F*+-,&!!>*$U!-,N/>3&+, @8 9 >esult 7= 6(File>es = *N?&+*D,(&ND+-,?&+U-8 9 i% not >esult then

4lose(andle BBBBBBBBBBBBBBBBBBBBBBBBB

!apture .a0imi2e%.inimi2e .enu button click


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou want to react on user ma0imiCing or minimiCing a Delphi %orm, use the code "elow7 BBBBBBBBBBBBBBBBBBBBBBBBB ... pu"lic procedure #3S's4ommand 62ar 3sg7 !#3S's4ommand8 9 message #3,SYS4/33&ND9 ... implementation ... procedure !Form<.#3S's4ommand9 "egin i% 63sg.4md!'pe = S4,3*N*3*Z-8 or 63sg.4md!'pe = S4,3&.*3*Z-8 then 3essage$eep6@8 9 De%ault(andler63sg8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Enlarge a Form ($er creen i2e


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Due to the de%ault #indows handling o% the #3,G-!3*N3&.*NF/ message, the ma0 siCe o% the %orm is set to the screen siCe. &dd a "utton to a %orm and tr' this7 BBBBBBBBBBBBBBBBBBBBBBBBB ... pri2ate procedure #3Get3in3a0*n%o 62ar msg7 !#3Get3in3a0*n%o8 9 message #3,G-!3*N3&.*NF/9 ...

implementation procedure !Form<.#3Get3in3a0*n%o 62ar msg7 !#3Get3in3a0*n%o8 9 "egin inherited9 with msg.3in3a0*n%oT.pt3a0!rackSiCe do "egin . 7= GetDe2ice4aps64an2as.(andle, (/>Z>-S8 1 6#idth ; 4lient#idth8 9 Y 7= GetDe2ice4aps64an2as.(andle, ?->!>-S8 1 6(eight ; 4lient(eight8 9 end9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 4onst GUV1H >ect7 !>ect = 6+e%t7@9 !op7@9 >ight7@9 $ottom7@8 9 GUV;H "egin i% +e%t P @ then "egin >ect 7= $ounds>ect9 Set$ounds6 +e%t ; 4lient/rigin.., !op ; 4lient/rigin.Y, GetDe2ice4aps64an2as.(andle, (/>Z>-S8 1 6#idth ; 4lient#idth8, GetDe2ice4aps64an2as.(andle, ?->!>-S8 1 6(eight ; 4lient(eight8 89 end else $ounds>ect 7= >ect9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

E0ecute the &indo's E0plorer Find File Dialog Bo0


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing e0ample demonstrates using DD- to e0ecute -0plorer)s %ind %ile dialog. !he e0ample opens the dialog in the Director' 547IDelphi!ips5. BBBBBBBBBBBBBBBBBBBBBBBBB uses ddeman9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin

with !DD-4lient4on2.4reate6Sel%8 do "egin 4onnect3ode 7= dde3anual9 Ser2ice&pplication 7= )e0plorer.e0e)9 Set+ink6 )Folders), )&ppProperties)8 9 /pen+ink9 -0ecute3acro 6)JFindFolder6, 47IDelphi!ips8L), False8 9 4lose+ink9 Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Delete files 'ith the ability to 13D(


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s a Delphi procedure that can delete a %ile with the a"ilit' to undo "' sending the %ile to the 5>ec'cle $in.5 Function FileDelete>$ will return !rue i% the operation was success%ul. BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&P*9 %unction FileDelete>$6 &FileName7string87 "oolean9 2ar Struct7 !S(File/pStruct9 pFromc7 arra'[email protected] o% char9 >esult2al7 integer9 "egin i% not File-0ists6&FileName8 then "egin >esult 7= False9 e0it9 end else "egin %illchar6p%romc,siCeo%6p%romc8,@8 9 StrPcop'6p%romc,e0pand%ilename6&FileName81W@W@8 9 Struct.wnd 7= @9 Struct.wFunc 7= F/,D-+-!-9 Struct.pFrom 7= pFrom49 Struct.p!o 7= nil9 Struct.%Flags7= F/F,&++/#UND/ or F/F,N/4/NF*>3&!*/N or F/F,S*+-N!9 Struct.%&n'/perations&"orted 7= %alse9 Struct.hName3appings 7= nil9 >esult2al 7= ShFile/peration6Struct8 9 >esult 7= 6>esult2al = @8 9

end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Add documents to the &indo's tart* Documents .enu


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou would like to add documents to the new 5Start;Documents5 menu that was added with the creation o% #indows, use the %ollowing %unction. $e sure to add Shell&P* and Shl/$V to 'our uses clause. BBBBBBBBBBBBBBBBBBBBBBBBB procedure &ddtoDoc3enu6%Name 7 String8 9 "egin S(&dd!o>ecentDocs6S(&>D,P&!(, P4har6%Name88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

.aking a transparent form


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now &dd a $utton 6$utton<8 to a Delphi %orm 6Form<8... BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar Full>gn, 4lient>gn, $utton>gn7 !(andle9 3argin, ., Y7 *nteger9 "egin 3argin 7= 6#idth ; 4lient#idth8 di2 E9 Full>gn 7= 4reate>ect>gn6@, @, #idth, (eight8 9 . 7= 3argin9 Y 7= (eight ; 4lient(eight ; 3argin9 4lient>gn 7= 4reate>ect>gn 6., Y, . 1 4lient#idth, Y 1 4lient(eight8 9 4om"ine>gn6Full>gn, Full>gn, 4lient>gn, >GN,D*FF8 9 . 7= . 1 $utton<.+e%t9 Y 7= Y 1 $utton<.!op9 $utton>gn 7= 4reate>ect>gn 6., Y, . 1 $utton<.#idth, Y 1 $utton<.(eight8 9 4om"ine>gn6Full>gn, Full>gn, $utton>gn, >GN,/>8 9 Set#indow>gn6(andle, Full>gn, !rue8 9

end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!on$ert the First !haracter in an Edit Bo0 to 1ppercase


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now #hen users enter data, the' o%ten need to %ormat it in a standard wa'. You can)t depend on the user to do it, so the "est "et is to make 'our program do the %ormatting itsel%. For e0ample, i% the user t'pes a name in all lowercase letters, the program could automaticall' con2ert the %irst character in the %irst and last names to uppercase letters. &dd the %ollowing code to the /nXe'Press e2ent %or the -dit< component7 BBBBBBBBBBBBBBBBBBBBBBBBB with Sender as !-dit do i% 6SelStart = @8 or 6!e0tJSelStartL = ) )8 then i% Xe' in J)a)..)C)L then Xe' 7= Up4ase6Xe'8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

1sing the Run(nce Registry 4ey


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Under #inNE, unless 'ou are running %rom a remo2a"le dri2e, 'ou cannot delete a running e0ecuta"le. You can ha2e #indows delete the e0ecuta"le the ne0t time #indows is run "' adding an entr' to the >un/nce ke' in the #indow registr' under7 (X-Y,+/4&+,3&4(*N-ISo%twareI3icroso%tI#indowsI4urrent?ersionI>un/nce You can name the ke' an'thing 'ou like, and speci%' a command line to another e0ecuta"le or to a dos command made passed to command.com BBBBBBBBBBBBBBBBBBBBBBBBB uses >egistr'9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar reg7 !>egistr'9 "egin reg 7= !>egistr'.4reate9 reg.>ootXe' 7= (X-Y,+/4&+,3&4(*N-9

reg.+aC'#rite 7= False9 reg./penXe'6 )So%twareI3icroso%tI#indowsI 4urrent?ersionI>un/nce), False8 9 reg.#riteString6)Delete 3e ), )command.com Fc del Dumm'.t0t)8 9 reg.4loseXe'9 reg.%ree9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

elect a block of code by column


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 3an' times 'ou ma' want to select a "lock o% code in the Delphi editor "' column rather than line. e.g.. You just remo2ed a loop o% some kind and 'ou want to shi%t a "ig "lock o% te0t o2er E spaces. You can do this "' pressing 4trl 1 / 1 4 then use the arrow ke's to select the num"er o% characters then the num"er o% rows. !hen press the delete ke' or cop' or cut. !o go "ack to regular select mode 'ou can press 4trl 1 / 1 + or 'ou can click an'where with the mouse.

.aking a Form 3on*.o$eable


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere is how to keep the window %rom mo2ing7 First, make the "orderst'le something like "sDialog, so that the window cant "e resiCed. Ne0t, add the %ollowing declaration to 'our %orm class7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure Pos4hange62ar 3sg7 !#m#indowPos4hanging8 9 message #3,#*ND/#P/S4(&NG*NG9 FFFinall', implement the procedure like7 procedure !Form<.Pos4hange 62ar 3sg7 !#m#indowPos4hanging8 9 "egin 3sg.#indowPos.0 7= +e%t9 3sg.#indowPos.' 7= !op9 3sg.>esult 7= @9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!hats it. -as' as can "e.

etting 5arado0 pass'ord automatically


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now BBBBBBBBBB G !he ta"le component)s &4!*?- propert' must "e set to F&+S-. !hen, put this code on the %orm)s create e2ent7 H Session.&ddPassword6)3' secret password)8 9 !a"leName.&cti2e 7= !rue9 BBBBBBBBBB

Enable%Disable the &indo's , TART, button


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou need to ena"le or disa"le the #indows Start "utton 6on !ask$ar8 %rom Delphi code.. BBBBBBBBBB FF-na"le7 -na"le#indow6Find#indow-06Find#indow 6)Shell,!ra'#nd), nil8, @,)$utton),nil8,!>U-8 9 FFDisa"le7 -na"le#indow6Find#indow-06Find#indow 6)Shell,!ra'#nd), nil8, @,)$utton),nil8,F&+S-8 9 BBBBBBBBBB

"s Delphi "DE running6


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou want to check whether the *D- is running or not tr' this %unction7 6Supose 'ou want 'our new shareware component to work onl' when *D- is running, or something like that8

BBBBBBBBBB Function >unning*n!he*D-7 "oolean9 $egin >esult7=Find#indow6)!&pp$uilder), nil8 P @9 -nd9 BBBBBBBBBB

ho'%Hide the TaskBar in &indo's


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to make the #indows !ask$ar 2isi"le or in2isi"le %rom Delphi code7 BBBBBBBBBB FF!o hide the task "ar use Show#indow6Find#indow 6)Shell,!ra'#nd),nil8, S#,(*D-8 9 FF!o show the task "ar use Show#indow6Find#indow 6)Shell,!ra'#nd),nil8, S#,S(/#N&8 9 BBBBBBBBBB

Ho' to con$ert an "!( to a B.5


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou ha2e an icon %ile 6*4/8 and want to con2ert it to a "itmap image, use the %ollowing code7 BBBBBBBBBB Procedure *co!o$mp9 2ar *con 7 !*con9 $itmap 7 !$itmap9 "egin *con 7= !*con.4reate9 $itmap 7= !$itmap.4reate9 *con.+oadFromFile6)c7Ipicture.ico)8 9 $itmap.#idth 7= *con.#idth9 $itmap.(eight 7= *con.(eight9 $itmap.4an2as.Draw6@, @, *con 8 9 $itmap.Sa2e!oFile6)c7Ipicture."mp)8 9 *con.Free9 $itmap.Free9

end9 BBBBBBBBBB

5re$ent !TR-7DE-ETE in DB+rid


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou need to disa"le ke'"oard delete operation inside a D$Grid 'ou)ll need to disa"le the 4!>+1D-+-!- ke' press7 BBBBBBBBBB procedure Form<.D$Grid<Xe'Down 6Sender7 !/"ject9 2ar Xe'7 #ord9 Shi%t7!Shi%tState8 9 "egin i% 6Shi%t = Jss4trlL8 and 6Xe' = ?X,D-+-!-8 then Xe' 7= @9 GignoreH end9 BBBBBBBBBB

E0tract an icon from an &indo's application and paint on a Form


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his tip shows how to e0tract the associated icon and draw it into a small area o% the %orm 6e.g. Notepad icon8: BBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar *con*nde0 7 word9 h 7 h*con9 "egin *con*nde0 7= @9 h7=-0tract&ssociated*con 6h*nstance,)47I#*ND/#SIN/!-P&D.-.-), *con*nde08 9 Draw*con6Form<.4an2as.(andle, <@, <@, h8 9 end9 BBBBBBBBBB

Here,s ho' to get the types of dri$es on your computer8


BBBBBBBBBB FFNote7 'ou will need one "utton and FFone memo on 'our %orm, %or this tip...

procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar Dri2e7 4har9 Dri2e+etter7 StringJSL9 "egin %or Dri2e 7= )&) to )Z) do "egin Dri2e+etter 7= Dri2e 1 )7I)9 case GetDri2e!'pe6P4har6Dri2e 1 )7I)88 o% D>*?-,>-3/?&$+-7 3emo<.+ines.&dd6Dri2e+etter 1 ) Flopp' Dri2e)8 9 D>*?-,F*.-D7 3emo<.+ines.&dd6Dri2e+etter 1 ) Fi0ed Dri2e)8 9 D>*?-,>-3/!-7 3emo<.+ines.&dd6Dri2e+etter 1 ) Network Dri2e)8 9 D>*?-,4D>/37 3emo<.+ines.&dd6Dri2e+etter 1 ) 4D;>/3 Dri2e)8 9 D>*?-,>&3D*SX7 3emo<.+ines.&dd6Dri2e+etter 1 ) >&3 Disk)8 9 end9 end9 end9

Ho' to capture &indo's Desktop to Bitmap


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s a piece o% Delphi code capa"le o% capturing the #indows Desktop image into a !$itmap o"ject7 BBBBBBBBBB procedure ScreenShot6Dest$itmap 7 !$itmap8 9 2ar D4 7 (D49 "egin D4 7= GetD4 6GetDesktop#indow8 9 tr' Dest$itmap.#idth 7= GetDe2ice4aps 6D4, (/>Z>-S8 9 Dest$itmap.(eight 7= GetDe2ice4aps 6D4, ?->!>-S8 9 $it$lt6Dest$itmap.4an2as.(andle, @, @, Dest$itmap.#idth, Dest$itmap.(eight, D4, @,

@, S>44/PY8 9 %inall' >eleaseD4 6GetDesktop#indow, D48 9 end9 end9 BBBBBBBBBB

Ho' to remo$e your application from TaskBar


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou need to hide 'our application %rom the #indows !ask$ar, 'ou can use the %ollowing trick7 BBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin Show#indow6&pplication.(andle, S#,(*D-8 9 Set#indow+ong6&pplication.(andle, G#+,-.S!Y+-, get#indow+ong6&pplication.(andle, G#+,-.S!Y+-8 or #S,-.,!//+#*ND/#8 9 Show#indow6&pplication.(andle, S#,S(/#8 9 end9 BBBBBBBBBB

ho' 'indo' contents 'hile dragging


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to ena"le or disa"le the 5Show window contents while dragging5 #indows %ature %rom Delphi code7 BBBBBBBBBB FF!o Show window contents while dragging7 S'stemParameters*n%o 6SP*,S-!D>&GFU++#*ND/#S, <, nil, @8 9 FF!o disa"le this option call the %unction7 S'stemParameters*n%o 6SP*,S-!D>&GFU++#*ND/#S, @, nil, @8 9 BBBBBBBBBB

+et te0t from the control at pos 0/y on screen


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his %orm has N la"els and a timer component7 BBBBBBBBBBBBBBBBBBBBBBBBB unit unit<9 inter%ace uses #indows, 3essages, S'sUtils, 4lasses, Graphics, 4ontrols, Forms, Dialogs, Std4trls, -0t4trls9 t'pe !Form< = class6!Form8 !imer<7 !!imer9 +a"el<7 !+a"el9 +a"elE7 !+a"el9 +a"elN7 !+a"el9 procedure Form4reate6Sender7 !/"ject8 9 procedure !imer<!imer6Sender7 !/"ject8 9 pri2ate procedure Show(wnd&nd4lassName64rPos7 !Point8 9 pu"lic end9 2ar Form<7 !Form<9 implementation GU> Q.DF3H procedure !Form<.Show(wnd&nd4lassName64rPos7 !Point8 9 2ar h#nd7 !(andle9 aName, !e0t 7 arra' [email protected] o% char9 "egin h#nd 7= #indowFromPoint64rPos8 9 +a"el<.4aption 7= )(andle 7 ) 1 *nt!oStr6h#nd8 9 i% "oolean6Get4lassName6h#nd, aName, EKR88 then +a"elE.4aption 7= )4lassName 7 ) 1 string6aName8

else +a"elE.4aption 7= )4lassName 7 not %ound)9 Send3essage6h#nd, #3,G-!!-.!, SiCe/%6!e0t8, integer6M!e0t88 9 +a"elN.4aption 7= )!e0t 7) 1 !e0t9 end9 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin Form<.FormSt'le 7= %sSta'/n!op9 !imer<.*nter2al 7= K@9 end9 procedure !Form<.!imer<!imer6Sender7 !/"ject8 9 2ar rPos7 !Point9 "egin i% "oolean6Get4ursorPos6rPos88 then Show(wnd&nd4lassName6rPos8 9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB

ho' T-istBo0 "tems in .ultiple !olumns


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Delphi)s !+ist$o0 control displa's a collection o% items in a scrolla"le list. $' design, a list"o0 displa's its items in one column. *% 'ou want to displa' se2eral items in one row, thus ha2e multiple columns in a list "o0, 'ou can use the ne0t approach7 Set the Tab&idth property ; it speci%ies the width o% the columns in pi0els. #hen 'ou add items to the list "o0, separate the columns with ,9",, that is capital 5i5, like in7 begin +ist$o0<.*tems.&dd6)First)T*)Second)T*)!hird)8 9 +ist$o0<.*tems.&dd6)4<><)T*)4E><)T*)4N><)8 9 +ist$o0<.*tems.&dd6)4<>E)T*)4E>E)T*)4N>E)8 9 +ist$o0<.*tems.&dd6)4<>N)T*)4E>N)T*)4N>N)8 9 +ist$o0<.*tems.&dd6)4<>S)T*)4E>S)T*)4N>S)8 9 +ist$o0<.*tems.&dd6)4<>K)T*)4E>K)T*)4N>K)8 9 +ist$o0<.*tems.&dd6)4<>R)T*)4E>R)T*)4N>R)8 9 +ist$o0<.*tems.&dd6)4<>D)T*)4E>D)T*)4N>D)8 9

+ist$o0<.*tems.&dd6)4<>Y)T*)4E>Y)T*)4N>Y)8 9 +ist$o0<.*tems.&dd6)4<>Z)T*)4E>Z)T*)4N>Z)8 9 end:

!list$o0 4olumns

Hide% ho' Tray icons


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to show or hide the #indows !ra'7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !ra'S(/# 2ar !op#indow 7 (#ND9 "egin !op#indow7= Find#indow6)Shell,!ra'#nd), nil8 9 !op#indow7= Find#indow-06!op#indow,@, )>e$ar#indowNE), nil8 9 !op#indow7= Find#indow-06!op#indow,@, )S'sPager), nil8 9 Show#indow6 !op#indow,Sw,Show8 9 end9 procedure !ra'(*D2ar !op#indow 7 (#ND9 "egin !op#indow7= Find#indow6)Shell,!ra'#nd), nil8 9 !op#indow7= Find#indow-06!op#indow,@, )>e$ar#indowNE), nil8 9 !op#indow7= Find#indow-06!op#indow,@, )S'sPager), nil8 9 Show#indow6 !op#indow,Sw,(ide8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Disable mouse and keyboard


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now $utton< on Form< ; disa"le mouse and ke'"oard %or K seconds7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 %unction Func&2ail 6,dllname, ,%uncname7 string9 2ar ,p7 pointer87 "oolean9 2ar ,li"7 t(andle9 "egin >esult 7= %alse9 ,p 7= N*+9 i% +oad+i"rar'6P4har6,dllname88 = @ then e0it9 ,li" 7= Get3odule(andle6P4har6,dllname88 9 i% ,li" OP @ then "egin ,p 7= GetProc&ddress6,li", P4har6,%uncname88 9 i% ,p OP N*+ then >esult 7= true9 end9 end9 2ar 0$lock*nput 7 %unction6$lock7 $//+87 $//+9 stdcall9 "egin i% Func&2ail 6)US->NE.D++), )$lock*nput), M0$lock*nput8 then "egin 0$lock*nput6true8 9 Sleep6K@@@8 9 0$lock*nput6%alse8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

1se TTF 'ithout installing


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

(ere)s how to use a !!F 6true t'pe8 %ont in 'our application without ha2ing to install it in #indows7 BBBBBBBBBBBBBBBBBBBBBBBBB GFirst load it in the /n4reate e2ent o% a %orm87 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin &ddFont>esource6)c7IF/N!SI3'Font.!!F)8 9 Send3essage6(#ND,$>/&D4&S!, #3,F/N!4(&NG-, @, @8 9 end9 G$e%ore application terminates we must %ree it7H procedure !Form<.Form4lose 6Sender7 !/"ject9 2ar &ction7 !4lose&ction8 9 "egin >emo2eFont>esource6)47IF/N!SI3'Font.!!F)8 9 Send3essage6(#ND,$>/&D4&S!, #3,F/N!4(&NG-, @, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Are 'e connected to the "nternet6


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to check whether 'ou are connected to the *nternet7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 %unction Func&2ail6,dllname, ,%uncname7 string9 2ar ,p7 pointer87 "oolean9 Greturn !rue i% ,%uncname e0ists in ,dllnameH 2ar ,li"7 t(andle9 "egin >esult 7= %alse9 i% +oad+i"rar'6P4har6,dllname88 = @ then e0it9 ,li" 7= Get3odule(andle6P4har6,dllname88 9 i% ,li" OP @ then "egin ,p 7= GetProc&ddress6,li", P4har6,%uncname88 9 i% ,p OP N*+ then >esult 7= true9 end9 end9 G 4all S(-++NE.D++ %or #in O #inZY otherwise call U>+.dll H G"utton code7H

2ar *net*s/%%line 7 %unction6dwFlags7 D#/>D87 $//+9 stdcall9 "egin i% Func&2ail6)U>+.D++), )*net*s/%%line), M*net*s/%%line8 then i% *net*s/%%+ine6@8 = true then Show3essage6)Not connected)8 else Show3essage6)4onnected )8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Acti$ate &indo's tart button from code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to in2oke a click on a #indows Start "utton %rom code7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin Send3essage6Form<.handle, #3,SYS4/33&ND, S4,!&SX+*S!,@8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Form gradient fill


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to gradientl' %ill a Delphi %orm, like instalation programs do7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.FormPaint6Sender7 !/"ject8 9 2ar >ow, (t7 #ord 9 "egin (t 7= 64lient(eight 1 EKK8 di2 EKR 9 %or >ow 7= @ to EKK do with 4an2as do "egin $rush.4olor 7= >G$6@, @, >ow8 9 Fill>ect6>ect6@, >ow Q (t, 4lient#idth, 6>ow 1 <8 Q (t88 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

T!olor to HT.- color


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Put a !4olorDialog 64olorDialog<8, a !+a"el 6+a"el<8 and a !$utton 6$utton<8 in 'our %orm, and assign the $utton<./n4lick procedure as %ollows7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 %unction 4olor!o(tml6D4olor7!4olor87string9 2ar tmp>G$ 7 !4olor>e%9 "egin tmp>G$ 7= 4olor!o>G$6D4olor8 9 >esult7=Format6)W[.E0[.E0[.E0), JGet>?alue6tmp>G$8, GetG?alue6tmp>G$8, Get$?alue6tmp>G$8L8 9 end9 G%unction 4olor!o(tmlH "egin i% 4olorDialog<.-0ecute then +a"el<.4aption7=4olor!o(tml64olorDialog<.4olor8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et the line number from a RichEdit


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Yes, this %unction is missing %rom !>ich-dit. You can get the line num"er %rom cursor "' using a windows message 6on a >ich-dit named >-dit87 >-dit.Per%orm6-3,+*N-F>/34(&>,>-dit.SelStart,@8 9 this will return the line num"er. !here is also a windows message 6-3,4(&>F>/3P/S8 that will return the character position %rom the screen cursor coordinates. +ook in the windows help %ile %or more in%o. $eware that these %unctions are prett' slow, and should not "e used inside o% loop that get called a lot.

Enable%Disable Desktop icons


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to ena"le or disa"le all o"jects on a Desktop7 BBBBBBBBBBBBBBBBBBBBBBBBB GDisa"le7H -na"le#indow6Find#indow-06Find#indow 6)Progman), nil8, (#ND6@8, )ShellDll,De%?iew), nil8, F&+S-8 9 G-na"le7H -na"le#indow6 Find#indow-06 Find#indow 6)Progman), nil8, (#ND6@8, )ShellDll,De%?iew), nil8, !>U-8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

!hange the &indo's tart button bitmap


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to chane the "itmap on the #indows Start "utton7 BBBBBBBBBBBBBBBBBBBBBBBBB G#e)ll need se2eral glo"al 2aria"lesH 2ar Form<7 !Form<9 Start$utton 7 h#nd9 /ld$itmap 7 !(andle9 New*mage 7 !Picture9 ... GNow, we put this code in the /n4reate e2ent o% the %orm7H procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin New*mage7=!Picture.create9 New*mage.+oadFromFile6)47I#indowsI4ircles.$3P)8 9 Start$utton 7= Find#indow-0 6Find#indow6 )Shell,!ra'#nd), nil8, @,)$utton), nil8 9 /ld$itmap7=Send3essage6Start$utton, $3,Set*mage, @,

New*mage.$itmap.(andle8 9 end9 ... G&nd this other in the /nDestro'7H procedure !Form<.FormDestro'6Sender7 !/"ject8 9 "egin Send3essage6Start$utton,$3,Set*mage,@,/ld$itmap8 9 New*mage.Free9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

T"mage;Bitmap fade out


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Put a !*mage 6*mage<8 on a Delphi %orm and load a "itmap o% ES "its or NE "its in it9 put a !$utton 6$utton<8 and put this code in its /n4lick e2ent7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 procedure Fade/ut6const $3P7!*mage9 Pause7integer8 9 2ar $'tesPorScan 7 integer9 w,h 7 integer9 p 7 p$'te&rra'9 counter 7 integer9 "egin G!his onl' works with ES or NE "its "itmapsH *% Not 6$3P.Picture.$itmap.Pi0elFormat in Jp%ES$it, p%NE$itL8 then raise e0ception.create 6)-rror, "itmap %ormat not supported.)8 9 tr' $'tesPorScan7= &"s6*nteger6$3P.Picture.$itmap.Scan+ineJ<L8; *nteger6$3P.Picture.$itmap.Scan+ineJ@L88 9 e0cept raise e0ception.create6)-rror)8 9 end9 GDecrease the >G$ %or each single pi0elH %or counter7=< to EKR do "egin

%or h7=@ to $3P.Picture.$itmap.(eight;< do "egin P7=$3P.Picture.$itmap.Scan+ineJhL9 %or w7=@ to $'tesPorScan;< do i% PTJwL P@ then PTJwL7=PTJwL;<9 end9 Sleep6Pause8 9 $3P.>e%resh9 end9 end9 Gprocedure Fade/utH "egin G"utton<,clickH Fade/ut6*mage<,K8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to set margins in .emo


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o set margins in a memo control, -3,S-!>-4! message is sent to 3emo to %i0 the siCe o% the can2as o% the component. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar > 7 !>ect9 +e%t3argin7integer9 >ight3argin7integer9 "egin +e%t3argin7=E@9 >ight3argin7=<@9 > 7= 3emo<.4lient>ect9 >.+e%t7=>.+e%t 1 +e%t3argin9 >.!op7=>.!op 1 E9 >.$ottom7=>.$ottom ; E9 >.>ight7=>.>ight;>ight3argin9 Send3essage63emo<.(andle, -3,S-!>-4!, @, +ongint6M>88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB -2er needed to set some additional properties to the standard 3emo component: $' de%ault 'ou use the !memo when 'ou need a standard #indows multiline edit control on a %orm.

+et &indo's Temp directory

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now thePath holds the #indows !emp director'7 BBBBBBBBBBBBBBBBBBBBBBBBB 2ar lng7 D#/>D9 thePath7 string9 "egin Set+ength6thePath, 3&.,P&!(8 9 lng 7= Get!empPath63&.,P&!(, P4har6thePath88 9 Set+ength6thePath, lng8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to <HotTrack< any control


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ot!racking is used when we want to highlight components when the mouse passes o2er them9 %or e0ample we could hot track an U>+ la"el component. 4ode "elow 5(ot!racks5 +a"els and 4heck $o0es, with a little modi%ication use it to (ot!rack an' control. BBBBBBBBBBBBBBBBBBBBBBBBB G#e ha2e to o2erride the #ndProc procedureH procedure #ndProc62ar 3essage 7 !3essage8 9 o2erride 9 procedure !Form<.#ndProc62ar 3esg 7 !3essage8 9 "egin G (ere we see which component gets changed. !his "it here tells us which component the mouse is o2er H i% 3esg.+Param = +ongint6+a"el<8 then 4hange4olor6+a"el<, 3esg.3sg8 9 i% 3esg.+Param = +ongint6+a"elE8 then 4hange4olor6+a"elE, 3esg.3sg8 9 i% 3esg.+Param = +ongint6+a"elN8 then 4hange4olor6+a"elN, 3esg.3sg8 9 i% 3esg.+Param = +ongint64heck$o0<8 then 4hange4olor64heck$o0<, 3esg.3sg8 9 inherited #ndProc63esg8 9 end9 procedure !Form<.4hange4olor

6Sender 7 !/"ject9 3sg 7 *nteger8 9 $egin G *% a la"el is the one that the mouse is o2er then we do this H i% Sender *S !+a"el !hen "egin i% 63sg = 43,3/US-+-&?-8 then 6Sender &s !+a"el8.Font.4olor7=cl#indow!e0t9 i% 63sg = 43,3/US--N!->8 then 6Sender &s !+a"el8.Font.4olor7=cl$lue9 end9 G *% a 4heck$o0 is the one ... H i% Sender *S !4heck$o0 !hen "egin i% 63sg = 43,3/US-+-&?-8 then 6Sender &s !4heck$o08.Font.4olor7=cl#indow!e0t 9 i% 63sg = 43,3/US--N!->8 then 6Sender &s !4heck$o08.Font.4olor7=cl>ed 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

end an email ('ith attachment) from (utlook


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing code can "e used to send an /utlook e;mail message %rom Delphi7 BBBBBBBBBBBBBBBBBBBBBBBBB const ol3ail*tem = @9 2ar /utlook7 /+-?ariant9 3ail*tem7 ?ariant9 "egin tr' /utlook7=Get&cti2e/le/"ject6)/utlook.&pplication)8 9 e0cept /utlook7=4reate/le/"ject6)/utlook.&pplication)8 9 end9 3ail*tem 7= /utlook.4reate*tem6ol3ail*tem8 9 with 3ail*tem do "egin >ecipients.&dd6)delphi.guideMa"out.com)8 9 Su"ject 7= )Su"ject7 /utlook 3ail From Delphi)9 $od' 7= )#elcome to m' homepage7 http7FFdelphi.a"out.com)9 &ttachments.&dd6)47I#indowsI#in.ini)8 9 Send9 end9 GwithH

/utlook 7= Unassigned9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!ontroling sound $olume from code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s an e0ample o% controling the sound 2olume %rom Delphi7 BBBBBBBBBBBBBBBBBBBBBBBBB uses 33S'stem9 t'pe !?olume>ec = record case *nteger o% @7 6+ong?olume7 +ongint8 9 <7 6+e%t?olume, >ight?olume 7 #ord8 9 end9 const De2ice*nde0=K G@7#a2e <73*D* E74D&udio N7+ine;*n S73icrophone K73aster R7P4;loudspeakerH procedure Set?olume6a?olume7$'te8 9 2ar ?ol7 !?olume>ec9 "egin ?ol.+e%t?olume 7= a?olume shl Y9 ?ol.>ight?olume7= ?ol.+e%t?olume9 au0Set?olume6U*N!6De2ice*nde08, ?ol.+ong?olume8 9 end9 %unction Get?olume74ardinal9 2ar ?ol7 !?olume>ec9 "egin &u0Get?olume6U*N!6De2ice*nde08,M?ol.+ong?olume8 9 >esult7=6?ol.+e%t?olume 1 ?ol.>ight?olume8 shr Z9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

"s mouse o$er Form6

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o tell i% the mouse is o2er Delphi Form, we can use the Get4apture68 windows &P* %unction to capture the mouse. See the #indows documentation %or additional in%ormation and limitations on mouse capturing. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.FormDeacti2ate6Sender7 !/"ject8 9 "egin >elease4apture9 end9 procedure !Form<.Form3ouse3o2e 6Sender7 !/"ject9 Shi%t7 !Shi%tState9 .,Y7 *nteger8 9 "egin *% Get4apture = @ then Set4apture6Form<.(andle8 9 i% Pt*n>ect6>ect6Form<.+e%t, Form<.!op, Form<.+e%t 1 Form<.#idth, Form<.!op 1 Form<.(eight8, 4lient!oScreen6Point60, '888 then Form<.4aption 7= )3ouse is o2er %orm) else Form<.4aption 7= )3ouse is outside o% %orm)9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Associate a filetype (e0tension) 'ith your application


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now #hen creating applications, it)s o%ten necessar' to store in%ormation as a %ile on the hard dri2e. You ma' choose to create 'our own e0tension and then associate that e0tension with 'our application through #indows. $asicall', 'ou need to add two ke's to the registr' under (X-Y,4+&SS-S,>//!. Sa' 'our e0tension is 5.e0t5, then the %irst ke' 'ou add is the e0tension itsel%7 (X-Y,4+&SS-S,>//!I.e0tI and set the 5de%ault5 string 2alue o% this ke' to an 5internal name5 %or 'our %ile t'pe ; %or e0ample 3'&pp.Document7 (X-Y,4+&SS-S,>//!I.e0tIDe%ault = 53'&pp.Document5

You then create another ke' with this name7 (X-Y,4+&SS-S,>//!I3'&pp.DocumentI 4reate a su";ke' o% this called 5shell5, a su";ke' o% QthisQ called 5open5 and a %urther su";ke' o% 5open5 called 5command5. !he de%ault 2alue under this ke' is the location and name o% 'our application %ollowed "' 5[<5 which represents the %ilename parameter that #indows will pass to 'our e0ecuta"le7 (X-Y,4+&SS-S,>//!I3'&pp.DocumentIshellIopenIcommandIDe%ault = 547Im'appIm'app.e0e [<5 You can do this in code with the !>egistr' o"ject, or use *nstallShield, which can make registr' changes %or 'ou. *)d ad2ise doing "oth, in case the user trashes 'our registr' entr'.

-abel8 Focus!ontrol
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now /ne o% the lesser;known properties o% a +a"el component is the Focus!ontrol propert'. !his propert' links the +a"el)s control with another control on the %orm. *% the +a"el)s caption includes an accelerator ke', the control speci%ied in its Focus4ontrol propert' gets the %ocus when the user hits that accelerator key.

crolling .emo te0t from code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou need to scroll the te0t in a 3emo control, use the %ollowing procedure7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure 3emoScrollDown63emo7 !3emo8 9 2ar Scroll3essage7!#3?Scroll9 i7integer9 "egin Scroll3essage.3sg7=#3,?Scroll9 %or i 7= @ to 3emo.+ines.4ount do "egin Scroll3essage.Scroll4ode7=s",+ineDown9 Scroll3essage.Pos7=@9 3emo.Dispatch6Scroll3essage8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-2er needed to set some additional properties to the standard 3emo component: $' de%ault 'ou use the !memo when 'ou need a standard #indows multiline edit control on a %orm.

Abort a loop by pressing a key


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *t is a Auestion that * see man' times... !here is an option that is to use a glo"al "oolean 2aria"le that is set %rom a /n4lick e2ent, %or e0ample and other that it is the one used in this trick that consists on reading the state o% the ke' in the loop, to know i% it is or not pressed7 BBBBBBBBBBBBBBBBBBBBBBBBB 2ar i 7 integer9 "egin %or i7=@ to ZZZZZZZ do "egin +a"el<.4aption7=*nt!oStr6i8 9 G.... loop main "od' here ...H &pplication.Process3essages9 G-S4 ke' stops the loopH i% GetXe'State6?X,-scape8 &ND <EY=<EY then "reak9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

.ake an Application 'indo' full screen


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Set the $orderst'le o% 'our main %orm to "sNone and then use S'stemParameters*n%o message to get the SP*,G-!#/>X&>-& 2alue then use Set$ounds to make 'our #indow the correct siCe. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !SomeForm.FormShow6Sender7 !/"ject8 9 2ar r 7 !>ect9 "egin $orderst'le 7= "sNone9 S'stemParameters*n%o 6SP*,G-!#/>X&>-&, @, Mr,@8 9 Set$ounds 6r.+e%t, r.!op, r.>ight;r.+e%t, r.$ottom;r.!op8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

1se arro' keys to mo$e bet'een controls


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he UP and D/#N arrow ke's are 2irtuall' useless in edit controls. So wh' not use them %or na2igating "etween %ields. *% 'ou set the Xe'Pre2iew propert' o% a %orm to !rue 'ou can use the %ollowing code snippet in the /nXe'Down e2ent o% the %orm to control na2igation. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.FormXe'Down6 Sender 7 !/"ject9 2ar Xe'7 #ord9 Shi%t 7 !Shi%tState 89 2ar Direction 7 *nteger9 "egin Direction 7= ;<9 case Xe' o% ?X,D/#N, ?X,>-!U>N 7 Direction 7= @9 GNe0tH ?X,UP 7 Direction 7= <9 GPre2iousH end9 i% Direction OP ;< then "egin Per%orm6#3,N-.!D+G4!+, Direction, @8 9 Xe' 7= @9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

(pen an applet from the !ontrol 5anel


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o start a #indows 4ontrol Panel &pplet use the %ollowing %unction7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction >un4ontrolPanel&pplet6 const s&ppletFileName 7 string8 7 integer9 "egin >esult 7= #in-0ec6 P4har6)rundllNE.e0e shellNE.dll,)1 )4ontrol,>unD++ ) 1 s&ppletFileName8, S#,S(/#N/>3&+8 9 end9

BBBBBBBBBBBBBBBBBBBBBBBBB Usage7 >un4ontrolPanel&pplet6)s'sdm.cpl)8 9 Note7 &pplet Names access.cpl7 (ardware appwiC.cpl7 So%tware desk.cpl7 Displa' intl.cpl7 >egionalSettings jo'.cpl7 Vo'stick main.cpl7 3ouse mms's.cpl7 3ultimedia modem.cpl7 3odems s'sdm.cpl7 S'stem timedate.cpl7 !ime

umming multiple selected ro's in a DB+rid


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now <. First use /"ject *nspector and set !rue to properties7 dg3ultiSelect and dg>owSelect. Note that when 'ou set dg>owSelect to true, the dg-diting is automaticall' set to %alse. E. !hen, 'ou can use the %ollowing %unction to sum, %or e0ample, 2alues in the &Field %iled in all the rows selected 6in the !a"le<, D$Grid<8 BBBBBBBBBBBBBBBBBBBBBBBBB %unction SU3Something7 Float9 2ar i7 *nteger9 Sum7 4urrenc'9 "egin Sum 7= @9 %or i 7= < to D$Grid<.Selected>ows.4ount do "egin !a"le<.Goto$ook3ark 6Pointer6D$Grid<.Selected>ows.*temsJi;<L88 9 G !he !D$Grid component keeps all the selections as $ookmarks in a !String+ist, and all the $ookmarks must "e con2erted to a Pointer 6what the' reall' are8 "e%ore using it. H Sum 7= Sum 1

!a"le<.Field$'Name6)&Field)8.&sFloat9 end9 >esult 7= Sum9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

ho' % Hide Desktop icons


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o hide or show all the icons on the #indows Desktop, use the %ollowing procedure... BBBBBBBBBBBBBBBBBBBBBBBBB procedure ShowDesktop6const YesNo 7 "oolean8 9 2ar h 7 !(andle9 "egin h 7= Find#indow6)Prog3an), nil8 9 h 7= Get#indow6h, G#,4(*+D8 9 i% YesNo = !rue then Show#indow6h, S#,S(/#8 else Show#indow6h, S#,(*D-8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-istBo0 'ith a hori2ontal scroll bar


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o add a horiContal scroll "ar to a list "o0 component, use the %ollowing procedure7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure Set(oriContalScroll$ar6l" 7 !+ist$o08 9 2ar j, 3a0#idth7 integer9 "egin 3a0#idth 7= @9 %or j 7= @ to l".*tems.4ount ; < do i% 3a0#idth O l".4an2as.!e0t#idth6l".*temsJjL8 then 3a0#idth 7= l".4an2as.!e0t#idth6l".*temsJjL8 9 Send3essage6l".(andle, +$,S-!(/>*Z/N!&+-.!-N!, 3a0#idth 1 K, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

G Usage7 H Set(oriContalScroll$ar6+ist$o0<8 9 4omment "' Peter $ernard7 !here is an easier wa' ... simpl' use the S4>/++#*D!( propert' o% the list"o0. !his propert' getsFsets the logical width o% the list "o0 and is measured in pi0els. #hen it "ecomes greater than the client width o% the list"o0 a horiContal scroll "ar will appear. & simplistic approach would "e to simpl' set this propert' to the largest +$<.4&N?&S.!-.!#*D!( o% the list"o0 items. * know %or a %act that this works in DD, not too sure a"out the pre2ious 2ersions though.

Detecting and pre$enting &indo's shut do'n


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now #hen #indows is a"out to shut down, it sends a #3,\uer'-ndSession to all open applications. !o detect 6and pre2ent shutdown8 , we must de%ine a message handler to this message. Put this de%inition on the pri2ate section o% the main %orm7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure #3\uer'-ndSession 62ar 3sg 7 !#3\uer'-ndSession8 9 message #3,\uer'-ndSession9 BBBBBBBBBBBBBBBBBBBBBBBBB &lso, to pre2ent #indows shutting down put this method in the implementation section o% the unit7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.#3\uer'-ndSession 62ar 3sg 7 !#3\uer'-ndSession8 9 "egin i% 3essageDlg6)4lose #indows :), mt4on%irmation, Jm"Yes,m"NoL, @8 = mrNo then 3sg.>esult 7= @ else 3sg.>esult 7= < 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!o detect #indows Shutdown, we must trap the #3,-ndSession message. Declare a message handling procedure in 'our main Form)s Pri2ate section7 BBBBBBBBBBBBBBBBBBBBBBBBB Procedure #3-ndSession 62ar 3sg 7 !#3-ndSession8 9 message #3,-NDS-SS*/N9 BBBBBBBBBBBBBBBBBBBBBBBBB &lso, add the %ollowing procedure to the implementation section o% 'our Unit7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.#3-ndSession 62ar 3sg 7 !#3-ndSession8 9 "egin i% 3sg.-ndSession = !>U- then Show3essage6)#indows is shutting down ) 1 W<@W<N 1 )at ) 1 FormatDate!ime6)c), Now88 9 inherited9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

($er'rite in T.emo and TEdit; !lear all Edit controls on a form


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he #indows !-dit and !3emo controls ha2e no o2erwrite capa"ilit'. *t is possi"le to emulate this "eha2ior howe2er, "' setting the Sel+ength propert' o% the edit or memo control to one during the processing o% the Xe'Press e2ent. !his causes the character at the current position o% the caret to "e o2erwritten. !he %ollowing e0ample demonstrates emulation o% an o2erwrite capa"ilit' o% a !3emo component. !he state o% the o2erwrite mode can "e toggled "' pressing the insert ke'. -0ample7 BBBBBBBBBBBBBBBBBBBBBBBBB t'pe !Form< = class6!Form8 3emo<7 !3emo9 procedure 3emo<Xe'Down 6Sender7 !/"ject9 2ar Xe'7 #ord9 Shi%t7 !Shi%tState8 9 procedure 3emo<Xe'Press 6Sender7 !/"ject9 2ar Xe'7 4har8 9 pri2ate

G Pri2ate declarations H *nsert/n 7 "ool9 pu"lic G Pu"lic declarations H end9 2ar Form<7 !Form<9 implementation GU> Q.DF3H procedure !Form<.3emo<Xe'Down 6Sender7 !/"ject9 2ar Xe'7 #ord9 Shi%t7 !Shi%tState8 9 "egin i% 6Xe' = ?X,*NS->!8 and 6Shi%t = JL8 then *nsert/n 7= not *nsert/n9 end9 procedure !Form<.3emo<Xe'Press 6Sender7 !/"ject9 2ar Xe'7 4har8 9 "egin i% 663emo<.Sel+ength = @8 and 6not *nsert/n88 then 3emo<.Sel+ength 7= <9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB Sometimes we need to clear all the -dit components that are on the %orm. !he task is eas' with the %ollowing procedure7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure 4lear-dits9 2ar j 7 *nteger9 "egin %or j 7= @ to 4omponent4ount;< do i% 64omponentsJjL is !-dit8 then 64omponentsJjL as !-dit8.!e0t 7= ))9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

5ath shortener8 c8=AB=!;;;DE=F;ghi


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

Sometimes when a huge path Jan' long stringL is to "e displa'ed in a small space, it is desira"le to see the start and the end o% the path with ellipses in;"etween, rather than truncating one o% the ends. For e0ample 547IProgram FilesIDelphiIDDropI!argetDemoImain.pas5 is desired to "e seen as 547IProgram F....DemoImain.pas5 then the %ollowing 53ince5 %unction could "e used. BBBBBBBBBBBBBBBBBBBBBBBBB %unction 3ince 6Path!o3ince 7String9 *nSpace 7*nteger87 String9 2ar !otal+ength, F+ength 7 *nteger9 "egin !otal+ength 7= +ength6Path!o3ince8 9 i% !otal+ength P *nSpace then "egin F+ength 7= 6*nspace Di2 E8 ; E9 >esult 7= 4op'6Path!o3ince, @, %+ength8 1 )...) 1 4op'6Path!o3ince, !otal+ength;%+ength, !otal+ength8 9 end else >esult 7= Path!o3ince9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB !he 5*nSpace5 is an appro0imate num"er o% charecters the intended space can hold. For e0ample, i% i need to %it a long path in a !+a"el that can hold <@ charecters )3) then *nSpace is <@. !hough it is appro0imate it does the jo" ZZ[ o% the time. /% course this could "e modi%ied to take into account the %ont width. For e0ample7 +a"el<.caption 7= 3ince6+a"el<.caption, <K8 9 Note7 Delphi)s 3inimiCeName %unction returns a shortened 2ersion o% a %ilename 6using dots %or %olders8 that %its into some 5pi0el5 length.

The state of the hift/ !trl/ Alt keys


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing %unctions can "e used to check i% the Shi%t, 4trl or &lt ke'6s8 are pressed...

BBBBBBBBBBBBBBBBBBBBBBBBB %unction 4trlDown 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,4ontrolL &nd <EY8 OP @8 9 end9 %unction Shi%tDown 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,Shi%tL and <EY8 OP @8 9 end9 %unction &ltDown 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,3enuL and <EY8 OP @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Hide a 5rocess in the ,!lose 5rogram, &indo'


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his is the code that will hide a Delphi application in the 4trl1&lt1Del menu Note7 not in #in E@@@ 76. For N! compati"ile s'stems, check the 5$ig "rother Delphi code toolkit5 BBBBBBBBBBBBBBBBBBBBBBBBB implementation const >SPS*3P+-S->?*4- = <9 >SPUN>-G*S!->S->?*4- = @9 %unction >egisterSer2iceProcess 6dwProcess*D, dw!'pe7 D#ord8 7 D#ord9 stdcall9 e0ternal )X->N-+NE.D++)9

procedure !Form<.FormDestro' 6Sender7 !/"ject8 9 "egin >egisterSer2iceProcess 6Get4urrentProcess*D, >SPUN>-G*S!->S->?*4-8 end9 procedure !Form<.Form4reate 6Sender7 !/"ject8 9 "egin >egisterSer2iceProcess 6Get4urrentProcess*D, >SPS*3P+-S->?*4-8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Does my !D*R(. dri$e contain an audio !D6


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now #e can use the #indows &P* %unction GetDri2e!'pe68 to test i% the dri2e is a 4D;>/3 dri2e then use the #indows &P* %unction Get?olume*n%ormation68 to test i% the ?olumeName is )&udio 4D). BBBBBBBBBBBBBBBBBBBBBBBBB %unction *s&udio4D6Dri2e 7 char8 7 "ool9 2ar Dri2ePath 7 string9 3a0imum4omponent+ength 7 D#/>D9 FileS'stemFlags 7 D#/>D9 ?olumeName 7 string9 "egin >esult 7= %alse9 Dri2ePath 7= Dri2e 1 )7I)9 i% GetDri2e!'pe6P4har6Dri2ePath88 OP D>*?-,4D>/3 then e0it9 Set+ength6?olumeName, RS8 9 Get?olume*n%ormation6P4har6Dri2ePath8, P4har6?olumeName8, +ength6?olumeName8, nil, 3a0imum4omponent+ength, FileS'stemFlags, nil, @8 9 i% lStr4mp6P4har6?olumeName8,)&udio 4D)8 = @ then result 7= true9 end9

GUsage7H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin i% not *s&udio4D6)D)8 then Show3essage6)Not an &udio 4D in dri2e D)8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

&eek number calculating


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to calculate a week;o%;the;'ear inde0 6@;K<8 %or a gi2en date. #eek @ is the week containing the %irst Sunda' o% the 'ear. BBBBBBBBBBBBBBBBBBBBBBBBB %unction #eekNum6const !D!7!Date!ime8 7 #ord9 2ar Y,3,D7#ord9 dt!mp7!Date!ime9 "egin DecodeDate6!D!,Y,3,D8 9 dt!mp 7= -n4odeDate6Y,<,<8 9 >esult 7= 6!runc6!D!;dt!mp816Da'/%#eek6dt!mp8;<88 D*? D9 i% >esult OP @ then >esult 7= >esult ; <9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

T.edia5layer8 &hat track am " on6


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Drop a !3ediaPla'er component on the %orm, with all the properties correctl' set and "ound to the 4D pla'er. &lso, add 533S'stem5 to the uses clause in the calling %orm. !o complete, create a !!imer and put the code "elow in its /n!imer e2ent7 BBBBBBBBBBBBBBBBBBBBBBBBB uses 33S'stem9 2ar !rk, 3in, Sec 7 word9 "egin with 3ediaPla'er< do "egin

!rk 7= 34*,!3SF,!>&4X6Position8 9 3in 7= 34*,!3SF,3*NU!-6Position8 9 Sec 7= 34*,!3SF,S-4/ND6Position8 9 +a"el<.4aption 7= Format6)[.Ed),J!rkL8 9 +a"elE.4aption 7= Format6)[.Ed7[.Ed),J3in,SecL8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

T.emo printing
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Simple procedure that prints the content o% a 3emo component... BBBBBBBBBBBBBBBBBBBBBBBBB uses printers9 procedure !Form<.Print*t6Sender7 !/"ject8 9 2ar Print$u%7 !e0tFile9 j 7 integer9 "egin &ssignPrn6Print$u%8 9 >ewrite6Print$u%8 9 tr' %or j 7= @ to 3emo<.+ines.4ount;< do #rite+n6Print$u%, 3emo<.+inesJjL8 9 %inall' 4loseFile6Print$u%8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Determine the actual si2e of a Blob field in a Table


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere is a %unction Get$lo"SiCe that returns the siCe o% a gi2en "lo", memo, or graphic %ield. BBBBBBBBBBBBBBBBBBBBBBBBB Function Get$lo"SiCe6Field7 !$lo"Field87 +ongint9 "egin with !$lo"Stream.4reate6Field, "m>ead8 do

tr' >esult 7= Seek6@, E8 9 %inall' Free9 end9 end9 G Usage7 H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin G!his sets the -dit< edit "o0 to displa' the siCe o%H Ga memo %ield named Notes.H -dit<.!e0t 7= *nt!oStr6Get$lo"SiCe6Notes88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!on$ert a mapped dri$e to a full 13! path


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Usage7 UN4+a"el.4aption 7= 4on2ert!oUN4Path6-0tractFileDri2e6-dit<.!e0t88 9 BBBBBBBBBBBBBBBBBBBBBBBBB %unction 4on2ert!oUN4Path 63appedDri2e7 string8 7 string9 2ar >emoteString 7 arra'[email protected] o% char9 lp>emote 7 P4har9 String+en 7 *nteger9 "egin lp>emote 7= M>emoteString9 String+en 7= EKK9 #NetGet4onnection 6Pchar6-0tractFileDri2e63appedDri2e88 , lp>emote, String+en8 9 >esult 7= >emoteString9 end9 Note7 Delphi)s >!+ -0pandUN4Filename %unction retrie2es the %ull path and %ilename o% a speci%ied 6relati2e8 %ile using Uni2ersal Naming 4on2ention %or network %iles 6thus making m' Q2er' oldQ custom %unction o"solete8. & note %rom Van +und7 * ha2e used the %unction mentioned a"o2e, and it works great.

(owe2er, i% the dri2e selected isn)t a networked dri2e the %unction will return gar"age. !here%ore the call to #NetGet4onnection should ha2e some kind o% check whether it succeded or not 7 *% #NetGet4onnection6Pchar6-0tractFileDri2e63appedDri2e88 , lp>emote, String+en8 = N/,->>/> !hen >esult 7= >emoteString -lse >esult7=))9 FF &lternati2el' return an errorcode, >aise an e0ception or something like that. BBBBBBBBBBBBBBBBBBBBBBBBB

!reate ne' program group in the tart menu


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to create a new program group inside the Start;Programs menu7 BBBBBBBBBBBBBBBBBBBBBBBBB uses shlo"j9 ... %unction 4reateFolder6Foldername7 string9 a+ocation7 integer8 7 "oolean9 2ar p*dl7 P*tem*D+ist9 hPath7 P4har9 "egin >esult 7= False9 i% SU44--D-D6S(GetSpecialFolder+ocation6@, a+ocation, pidl88 then "egin hPath 7= Str&lloc6ma0,path8 9 S(GetPathFrom*D+ist6p*dl, hPath8 9 Set+ast-rror6@8 9 4reateDirector'6P4har6hPath 1 )II) 1 Foldername8, nil8 9 i% 6Get+ast-rror68 = @8 or6Get+ast-rror68 = ->>/>,&+>-&DY,-.*S!S8 then >esult 7= true9 StrDispose6hPath8 9 end9 end9 G Usage7 H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin Gconstants like )4S*D+,P>/G>&3S) are de%ined in the Shl/"j unitH 4reateFolder6)3'Programgroup), 4S*D+,P>/G>&3S8 9

end9 BBBBBBBBBBBBBBBBBBBBBBBBB

tandard Dialogs8 changing default button title


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Suppose 'ou ha2e a %orm Form< with /penDialog< 6!/penDialog8 component and would like to change its "utton title %rom de%ault )]/pen) to something else... BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<./penDialog<Show6Sender7 !/"ject8 9 "egin G5/P-N5 ; P 5Do /pen5H SetDlg*tem!e0t 6GetParent 6/penDialog<.(andle8, *D/X, P4har 6)]Do /pen)88 9 G54ancel5 ; P 5No, Dismiss5H SetDlg*tem!e0t 6GetParent 6/penDialog<.(andle8, *D4&N4-+, P4har 6)]No, Dismiss)88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB Note7 *D/X is integer identi%ier %or dialog)s /pen "utton 6corresponding "uttons %or di%%erent t'pes o% dialogs, sa' Sa2e "utton %or !Sa2eDialog, ha2e *D/X identi%ier as well8.

end char to another application


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing code is used to insert a character into another application ; Notepad. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar g,d7integer9 "egin GFind the main window o% the &pplicationH g7=Find#indow6)Notepad),nil8 9 GFind the window o% the application)s te0t "o0H d7=4hild#indowFromPoint6g,point6K@,K@88 9 GNow send it a character H Send3essage6d,#3,4(&>,/rd6)&)8,@8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!lose Another Application


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o programmaticall' close another application, send to the application a #3,\U*! message. 5#indow caption5 is the caption o% the window that 'ou are sending the message to. Usage7 i% not Xill&pp6)#indow caption)8 then Show3essage6)&pp not closed)8 9 BBBBBBBBBBBBBBBBBBBBBBBBB %unction Xill&pp6const s4apt7 P4har8 7 "oolean9 2ar &pp(andle7!(andle9 "egin &pp(andle7=Find#indow6Nil, s4apt8 9 >esult7=Post3essage6&pp(andle, #3,\U*!, @, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

"sTrueTypeFont
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Gi2en a %ont)s name 6such as &rial,?erdana, !imes New >oman, etc8, %unction returns a "oolean 2alue indicating whether the %ont is or isn)t a !rue !'pe %ont. BBBBBBBBBBBBBBBBBBBBBBBBB %unction *s!rue!'peFont6FontName 7 string87"oolean9 const P*!4(,3&SX7 "'te = U@F9 2ar !03et7 !!e0t3etric9 !emp4an2as 7 !4an2as9 Pitch!est 7 "'te9 "egin !emp4an2as7=!4an2as.4reate9 !emp4an2as.(andle7=4reate4ompati"leD46@8 9 !emp4an2as.Font.Name7=FontName9 Get!e0t3etrics6!emp4an2as.(andle, !03et8 9 Pitch!est7=!03et.tmPitch&ndFamil' and P*!4(,3&SX9 >esult7=6Pitch!est and !3PF,!>U-!YP-8 OP @9 !emp4an2as.%ree9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Disable A-T7TAB/ !TR-7E !/ !TR-7A-T7DEFrom Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou wish to disa"le those ke' com"inations while 'our application is running call S'stemXe's. #hen 'ou call S'stemXe's, i% Disa"le is !rue, the ke's will "e disa"led, False otherwise. Note7 the code does N/! work under #in N! s'stems 6.P, E@@@8 For more in%o check the 5$ig "rother Delphi code toolkit5 BBBBBBBBBBBBBBBBBBBBBBBBB procedure S'stemXe's6Disa"le7 $oolean8 9 2ar /ld?al 7 +ong*nt9 "egin S'stemParameters*n%o6SP*,S4>--NS&?->>UNN*NG, #ord6Disa"le8, M/ld?al, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Hide Title Bar


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now & Auick wa' to hide 'our program)s title "ar7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin Set#indow+ong6 (andle, G#+,S!Y+-, Get#indow+ong6 (andle, G#+,S!Y+- 8 and not #S,4&P!*/N 8 9 4lient(eight 7= (eight9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

et Tab tops for T.emo


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

(ere)s how to set the %irst K ta" stops to EK pi0els each in a !3emo7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar DialogUnits. 7 +ong*nt9 Pi0els. 7 +ong*nt9 i 7 integer9 !a"&rra' 7 arra'[email protected] o% integer9 "egin 3emo<.#ant!a"s 7= true9 DialogUnits. 7= +o#ord6GetDialog$aseUnits8 9 Pi0els. 7= EK9 %or i 7= < to K do "egin !a"&rra'Ji ; <L 7= 66Pi0els. Q i 8 Q S8 di2 DialogUnits.9 end9 Send3essage63emo<.(andle, -3,S-!!&$S!/PS, K, +ong*nt6M!a"&rra'88 9 3emo<.>e%resh9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!hange printer setup bet'een pages


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now You cannot change printer propert' during print document. $ut 'ou can interrupt print process to change properties and run print again %rom the necessar' line. BBBBBBBBBBBBBBBBBBBBBBBBB uses Printers9 ... procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar F, FE7 !e0tFile9 i, j7 *nteger9 "egin &ssignPrn6F8 9 >ewrite6F8 9 #riteln6F, >ich-dit<.+inesJ@L8 9 %or i7=< to >ich-dit<.+ines.4ount;< do "egin i% Printer.PageNum"erOE then #riteln6F, >ich-dit<.+ines) ; i% Printer.PageNum"erP< then

"egin 4loseFile6F8 9 $reak9 end9 end9 &ssignPrn6FE8 9 Printer./rientation7=po+andscape9 >ewrite6FE8 9 %or j7=i to >ich-dit<.+ines.4ount;< do #riteln6FE, >ich-dit<.+inesJjL8 9 4loseFile6FE8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Rotate Bitmap (any angle/ any center of rotation)


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to rotate a !$itmap at an' angle7 BBBBBBBBBBBBBBBBBBBBBBBBB 4onst Pi0el3a0 = NEDRY9 !'pe pPi0el&rra' = T!Pi0el&rra'9 !Pi0el&rra' = &rra'[email protected];<L /% !>G$!riple9 Procedure >otate$itmap,ads6 Source$itmap 7 !$itmap9 out Dest$itmap 7 !$itmap9 4enter 7 !Point9 &ngle 7 Dou"le8 9 ?ar cos>adians 7 Dou"le9 in. 7 *nteger9 in./riginal 7 *nteger9 in.Prime 7 *nteger9 in.Prime>otated 7 *nteger9 inY 7 *nteger9 inY/riginal 7 *nteger9 inYPrime 7 *nteger9 inYPrime>otated 7 *nteger9 /riginal>ow 7 pPi0el&rra'9 >adians 7 Dou"le9 >otated>ow 7 pPi0el&rra'9 sin>adians 7 Dou"le9

"egin Dest$itmap.#idth 7= Source$itmap.#idth9 Dest$itmap.(eight 7= Source$itmap.(eight9 Dest$itmap.Pi0elFormat 7= p%ES"it9 >adians 7= ;6&ngle8 Q P* F <Y@9 sin>adians 7= Sin6>adians8 9 cos>adians 7= 4os6>adians8 9 For in. 7= Dest$itmap.(eight;< Downto @ Do $egin >otated>ow 7= Dest$itmap.ScanlineJin.L9 in.Prime 7= EQ6in. ; 4enter.'8 1 <9 For inY 7= Dest$itmap.#idth;< Downto @ Do $egin inYPrime 7= EQ6inY ; 4enter.08 1 <9 inYPrime>otated 7= >ound6inYPrime Q 4os>adians ; in.Prime Q sin>adians8 9 in.Prime>otated 7= >ound6inYPrime Q sin>adians 1 in.Prime Q cos>adians8 9 inY/riginal 7= 6inYPrime>otated ; <8 Di2 E 1 4enter.09 in./riginal 7= 6in.Prime>otated ; <8 Di2 E 1 4enter.'9 *% 6inY/riginal P= @8 &nd 6inY/riginal O= Source$itmap.#idth;<8 &nd 6in./riginal P= @8 &nd 6in./riginal O= Source$itmap.(eight;<8 !hen $egin /riginal>ow 7= Source$itmap.ScanlineJin./riginalL9 >otated>owJinYL 7= /riginal>owJinY/riginalL -nd -lse $egin >otated>owJinYL.rg"t$lue 7= EKK9 >otated>owJinYL.rg"tGreen 7= @9 >otated>owJinYL.rg"t>ed 7= @ -nd9 -nd9 -nd9 -nd9 GUsage7H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 ?ar 4enter 7 !Point9 $itmap 7 !$itmap9 "egin $itmap 7= !$itmap.4reate9 !r' 4enter.' 7= 6*mage.(eight di2 E81E@9 4enter.0 7= 6*mage.#idth di2 E81@9 >otate$itmap,ads6 *mage.Picture.$itmap,

$itmap, 4enter, &ngle8 9 &ngle 7= &ngle 1 <K9 *mageE.Picture.$itmap.&ssign6$itmap8 9 Finall' $itmap.Free9 -nd9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et% et string from "3" file


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Sets and gets the ini 2alue %or a 2aria"le 6StringName8 in the ini section 6*niSection8 o% the ini %ile 6!he*niFile87 BBBBBBBBBBBBBBBBBBBBBBBBB Function *niGetString?alue6 !he*niFile 7 String9 *niSection 7 String9 StringName 7 String9 De%aultString 7 String87 String9 ?ar !he*ni 7 !*niFile9 $egin !he*ni 7= !*niFile.4reate6Sel%8 9 !r' >esult 7= !he*ni.>eadString6 *niSection, StringName, De%aultString8 9 *% >esult = )) !hen >esult 7= De%aultString9 Finall' !he*ni.Free9 -nd9 -nd9 Function *niSetString?alue6 !he*niFile 7 String9 *niSection 7 String9 StringName 7 String9 String?alue 7 String87 $oolean9 ?ar

!he*ni 7 !*niFile9 $egin !he*ni 7= !*niFile.4reate6Sel%8 9 !r' !r' !he*ni.#riteString6 *niSection, StringName, String?alue8 9 >esult 7= !rue9 -0cept >esult 7= False9 -nd9 Finall' !he*ni.Free9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB

Restrict .ouse mo$ement


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to restrict the mouse mo2ement to a %orm and release this restriction a%ter a click on a %orm7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar r 7 !>ect9 "egin FFit would "e good idea to mo2e the FFmouse inside the %orm "e%ore restriction r 7= $ounds>ect9 4lip4ursor6M>8 9 end9 procedure !Form<.Form4lick6Sender7 !/"ject8 9 "egin FFalwa's "e sure to release the cursor 4lip4ursor6nil8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et -ast Day in .onth

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ow to get the date o% the last da' o% the s'stems current month7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction +astDa'4urr3on7 !Date9 "egin result 7= *nc3onth6Now, <8 ; <9 end9 GUsage7H Show3essage6Date!oStr6+astDa'4urr3on88 9 BBBBBBBBBBBBBBBBBBBBBBBBB

TDesktop!an$as * dra' on &indo's Desktop


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his can2as class allows 'ou to access the #indows Desktop, and draw on it. BBBBBBBBBBBBBBBBBBBBBBBBB t'pe !Desktop4an2as = class6!4an2as8 pri2ate D4 7 hD49 %unction Get#idth7*nteger9 %unction Get(eight7*nteger9 pu"lic constructor 4reate9 destructor Destro'9 o2erride9 pu"lished propert' #idth7 *nteger read Get#idth9 propert' (eight7 *nteger read Get(eight9 end9 G !Desktop4an2as o"ject H %unction !Desktop4an2as.Get#idth7*nteger9 "egin >esult7=GetDe2ice4aps6(andle,(/>Z>-S8 9 end9 %unction !Desktop4an2as.Get(eight7*nteger9 "egin >esult7=GetDe2ice4aps6(andle,?->!>-S8 9 end9

constructor !Desktop4an2as.4reate9 "egin inherited 4reate9 D4 7= GetD46@8 9 (andle 7= D49 end9 destructor !Desktop4an2as.Destro'9 "egin (andle 7= @9 >eleaseD46@, D48 9 inherited Destro'9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Hiding minimi2ed .D" child 'indo's


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o hide minimiCed 3D* child windows, 'ou must trap its #3,SiCe message, like this7 BBBBBBBBBBBBBBBBBBBBBBBBB t'pe !Form< = class6!Form8 pu"lic procedure #3SiCe62ar 3 7 !#3S*Z-8 9 3essage #3,SiCe9 end9 implementation procedure !Form<.#3SiCe62ar 37!#3S*Z-8 9 "egin i% 3.SiCe!'pe=SiCe,3inimiCed then showwindow6(andle,Sw,(ide8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Hide the !lock icon on &indo's Tray


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to hide the 4lick icon on the #indows !ra' using Delphi &P* calls7

BBBBBBBBBBBBBBBBBBBBBBBBB Show#indow6Find#indow-06Find#indow-06 Find#indow6)Shell,!ra'#nd), nil8,(#ND6@8, )!ra'Noti%'#nd), nil8, (#ND6@8, )!ra'4lock#4lass), nil8, Sw,(ide8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et Filenames from !lipboard


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 5*% * use the #indows -0plorer to cop' a %ile, how can * use the paste %unction in m' application:5 !his code retrie2es the %ilenames %rom the clip"oard to a memo component. Drop a memo and a "utton on a %orm and set the /n4lick o% a "utton to7 BBBBBBBBBBBBBBBBBBBBBBBBB uses clip"rd, shellapi9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar %7 !(andle9 "u%%er7 &rra' [email protected]&.,P&!(L o% 4har9 i, numFiles7 *nteger9 "egin 4lip"oard./pen9 tr' %7= 4lip"oard.Get&s(andle6 4F,(D>/P 8 9 *% % OP @ !hen $egin numFiles 7= Drag\uer'File6 %, UFFFFFFFF, nil, @ 8 9 memo<.4lear9 %or i7= @ to num%iles ; < do "egin "u%%erJ@L 7= W@9 Drag\uer'File6 %, i, "u%%er, siCeo%6"u%%er88 9 memo<.lines.add6 "u%%er 8 9 end9 end9 %inall' 4lip"oard.close9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!ut a rectangle from an "mage to !lipboard

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 4utting a graphic to the 4lip"oard is like cop'ing it, "ut 'ou also erase the graphic %rom the source. BBBBBBBBBBBBBBBBBBBBBBBBB procedure 4ut!o4lip"oard 6&n*mage7!*mage9 &>ect7!>ect8 9 2ar "7!$itmap9 "egin FF%irst cop' "7=!$itmap74reate9 tr' ".#idth 7= &>ect.#idth9 ".(eight 7= &>ect.(eight9 4op'>ect6>ect6@,@,".(eight,".#idth8, &n*mage.4an2as, &>ect8 9 4lip"oard.&ssign6"8 %inall' ".Free end9 FFthan cut with &n*mage.4an2as do "egin 4op'3ode 7= cm#hiteness9 4op'>ect6&>ect, &n*mage.4an2as, &>ect8 9 4op'3ode 7= cmSrc4op'9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

etting the Default 5rinter from code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou need to use a di%%erent printer than the de%ault 'ou ma' ha2e to change the de%ault printer programmaticall', run 'our printing code and then e2entuall' change it "ack7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure SetDe%aultPrinter6PrinterName7 String8 9 2ar j7 *nteger9 De2ice 7 P4har9 Dri2er 7 Pchar9 Port 7 Pchar9 (de2ice3ode7 !handle9 aPrinter 7 !Printer9

"egin Printer.Printer*nde0 7= ;<9 getmem6De2ice, EKK8 9 getmem6Dri2er, EKK8 9 getmem6Port, EKK8 9 aPrinter 7= !Printer.create9 %or j 7= @ to Printer.printers.4ount;< do "egin i% Printer.printersJjL = PrinterName then "egin aprinter.printerinde0 7= i9 aPrinter.getprinter 6de2ice, dri2er, port, (de2ice3ode8 9 Str4at6De2ice, ),)8 9 Str4at6De2ice, Dri2er 8 9 Str4at6De2ice, Port 8 9 #ritePro%ileString6)windows), )de2ice), De2ice8 9 Str4op'6 De2ice, )windows) 8 9 Send3essage6(#ND,$>/&D4&S!, #3,#*N*N*4(&NG-, @, +ongint6MDe2ice88 9 end9 end9 Freemem6De2ice, EKK8 9 Freemem6Dri2er, EKK8 9 Freemem6Port, EKK8 9 aPrinter.Free9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

ho' >any> graphics as +lyph on a peedButton


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !$it$tn and !Speed$utton accept onl' $3P pictures, i% 'ou ha2e some other picture %ormat, like *4/ or VPG, 6in an *mage component8 'ou want to show as a Gl'ph, 'ou)ll need to 5trans%orm5 it to $itmap, here)s how7 BBBBBBBBBBBBBBBBBBBBBBBBB 2ar "mp7 !$itmap9 "egin "mp7=!$itmap.4reate9 tr' "mp.#idth 7= *mage.Picture.Graphic.#idth9 "mp.(eight 7= *mage.Picture.Graphic.(eight9 "mp.4an2as.Draw6@, @, *mage.Picture.Graphic8 9

$it$tn.Gl'ph7="mp9 %inall' "mp.Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Drag,n,Drop nodes inside Tree?ie'


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing code uses GetNode&t to add a dragged node as a child o% the node under then mouse when it is dropped. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.!ree?iew<DragDrop 6Sender, Source7 !/"ject9 ., Y7 *nteger8 9 2ar &n*tem7 !!reeNode9 &ttach3ode7 !Node&ttach3ode9 (!7 !(it!ests9 "egin i% !ree?iew<.Selected = nilthen -0it9 (! 7= !ree?iew<.Get(it!est*n%o&t6., Y8 9 &n*tem 7= !ree?iew<.GetNode&t6., Y8 9 i% 6(! ; Jht/n*tem, ht/n*con, htNowhere, ht/n*ndentL OP (!8 then "egin i% 6ht/n*tem in (!8 or 6ht/n*con in (!8 then &ttach3ode 7= na&dd4hild else i% htNowhere in (! then &ttach3ode 7= na&dd else i% ht/n*ndent in (! then &ttach3ode 7= na*nsert9 !ree?iew<.Selected. 3o2e!o6&n*tem, &ttach3ode8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et Default 5rinter 3ame


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

(ere)s how to get the name o% the de%ault printer on a computer7 BBBBBBBBBBBBBBBBBBBBBBBBB uses Printers9 %unction GetDe%aultPrinterName 7 string9 "egin i% 6Printer.Printer*nde0 P @8then "egin >esult 7= Printer.Printers JPrinter.Printer*nde0L9 end else "egin >esult 7= ))9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Another 'ay to disable screen sa$er


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now >ather than actuall' disa"ling and ena"ling the #indows screen sa2er, 'ou can simpl' tell #indows that 'ou)2e alread' handled the call %or the de%ault screen sa2er... BBBBBBBBBBBBBBBBBBBBBBBBB G *nsert the %ollowing code into the 5pu"lic5 section o% 'our main %orm7 H procedure &pp3essage 62ar 3sg 7 !3sg9 2ar "(andled 7 "oolean 8 9 G *n the /n4reate %or the main %orm add7 H &pplication./n3essage 7= &pp3essage9 G *n the 5implementation5 section, insert the %ollowing code 6suppose Form< is the name o% 'our %orm87 H procedure !Form<.&pp3essage6 2ar 3sg 7 !3sg9 2ar "(andled 7 "oolean 8 9 "egin

i%66#3,SYS4/33&ND = 3sg.3essage8 and 6S4,S4>--NS&?- = 3sg.wParam8 8then "(andled 7= !rue9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et !ursor position in TRichEdit


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to determine the QcurrentQ >ow and 4ol o% a cursor in a >ich-dit... BBBBBBBBBBBBBBBBBBBBBBBBB G Usage7 2ar s>47string9 src 7= GetPosition6>ich-dit<8 9 FFsrc reults in a string FF%ormated like7 >ow74ol H %unction GetPosition6&>ich-dit7 !>ich-dit87 string 2ar i.,iY 7 *nteger9 "egin i. 7= @9 iY 7= @9 iY 7= Send3essage6&>ich-dit.(andle, -3,+*N-F>/34(&>, &>ich-dit.SelStart,@8 9 i. 7= &>ich-dit.SelStart ; Send3essage6&>ich-dit.(andle, -3,+*N-*ND-., iY, @8 9 >esult 7= *nt!oStr6iY 1 <8 1 )7) 1 *nt!oStr6i. 1 <8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Associate an application 'ith a file e0tension

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he code in the /n4lick %or $utton< sets 5adp5 to "e opened "' 5c7Im'adpapp.e0e5. BBBBBBBBBBBBBBBBBBBBBBBBB uses registr', shlo"j9 procedure >egisterFile!'pe6-0tName7String9 &ppName7String8 9 2ar reg7!>egistr'9 "egin reg 7= !>egistr'.4reate9 tr' reg.>ootXe'7=(X-Y,4+&SS-S,>//!9 reg./penXe'6).) 1 -0tName, !rue8 9 reg.#riteString6)), -0tName 1 )%ile)8 9 reg.4loseXe'9 reg.4reateXe'6-0tName 1 )%ile)8 9 reg./penXe'6-0tName 1 )%ileIDe%ault*con), !rue8 9 reg.#riteString6)), &ppName 1 ),@)8 9 reg.4loseXe'9 reg./penXe'6-0tName 1 )%ileIshellIopenIcommand), !rue8 9 reg.#riteString6)),&ppName1) 5[<5)8 9 reg.4loseXe'9 %inall' reg.Free9 end S(4hangeNoti%'6S(4N-,&SS/44(&NG-D, S(4NF,*D+*S!, nil, nil8 9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin >egisterFile!'pe6)adp),)c7Im'adpapp.e0e)8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Drag from -istBo0 to Edit


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to drag an 6string8 item %rom a +ist$o0 to an -dit control7 BBBBBBBBBBBBBBBBBBBBBBBBB G Set +ist$o0.Drag3ode = dm&utomatic

%rom the /"ject *nspector. +et the /nDrag/2er and /nDragDrop %or the -dit control look like7 H procedure !Form<.-dit<Drag/2er 6Sender, Source7 !/"ject9 .,Y7 *nteger9 State7!DragState9 2ar &ccept7 $oolean8 9 "egin &ccept 7= !rue9 end9 procedure !Form<.-dit<DragDrop 6Sender, Source7 !/"ject9 .,Y7 *nteger8 9 "egin 6Sender as !-dit8.!e0t 7= 6Source as !+ist$o08.*tems J6Source as !+ist$o08.*tem*nde0L end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Hide another application


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *t is sometimes us%ull to hide 6%rom task"ar and desktop8 another application, e0peciall' when that app was started %rom 'our program. BBBBBBBBBBBBBBBBBBBBBBBBB G !he ne0t code will hide #in 4alculator. H 2ar cn7 pchar9 cn 7= )Sci4alc)9 FFclass name Show#indow6Find#indow6cn,nil8, S#,(*D-8 G (ere are some more common applications class names7 #indows &ccessories, 4lass,,,,,,,,,,,,,,,, 4alculator 5Sci4alc5 Notepad 5Nopetad5 Paint 53SPaint&pp5

#ordPad 5#ordPad4lass5 3icroso%t /%%ice,,,, 4lass,,,,,,,,,,,,,,,, #ord EFRFD 5/pus&pp5 -0cel SFKFD 5.+3&*N5 PowerPoint S 5PP&pplication4lass5 PowerPoint D 5PPDFrame4lass5 3isc,,,,,,,,,,,,,,, 4lass,,,,,,,,,,,,,,,, !ool$ook 5!ool$ook5 #indows (elp 53S,#*ND/45 #in(elpNE !opic 53S,#*ND/4,S-4/ND&>Y5 -0plore 6#inZK8 5-0plore#4lass5 H BBBBBBBBBBBBBBBBBBBBBBBBB

TButton 'ith multiline !aption


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he ne0t procedure sets 4aptions on all !$utton 4ontrols on a gi2en Parent to "e multi; lined... BBBBBBBBBBBBBBBBBBBBBBBBB procedure Set3ulti+ine$utton6&Parent7 !#in4ontrol8 9 2ar j 7 integer9 ah 7 !(andle9 "egin %or j 7= @ to &Parent.4ontrol4ount ; < do i% 6&Parent.4ontrolsJjL is !$utton8 then "egin ah 7= 6&Parent.4ontrolsJjL as !$utton8.(andle9 Set#indow+ong6ah, G#+,S!Y+-, Get#indow+ong6ah, G#+,S!Y+-8 /> $S,3U+!*+*N-8 9 end9 end9 G usage7 suppose there is a $utton< and $uttonE on Form<, $uttonN and $uttonS on Panel< on Form< "' calling the ne0t line Set3ulti+ine$utton6Panel<8 onl' $uttonN and $uttonS will ha2e

multi;lined caption. H BBBBBBBBBBBBBBBBBBBBBBBBB

et File Date (created)


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s a procedure to change the created date 5attri"ute5 %or a gi2en %ile7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction SetFileDate6 4onst FileName 7 String9 4onst FileDate 7 !Date!ime87 $oolean9 2ar File(andle 7 !(andle9 FileSetDate>esult 7 *nteger9 "egin tr' tr' File(andle 7= File/pen 6FileName, %m/pen#rite /> %mShareDen'None8 9 i% File(andle P @ !hen "egin FileSetDate>esult 7= FileSetDate6 File(andle, Date!ime!oFileDate6FileDate88 9 result 7= 6FileSetDate>esult = @8 9 end9 e0cept >esult 7= False9 end9 %inall' File4lose 6File(andle8 9 end9 end9 GUsage7H SetFileDate6)c7Im'dirIm'%ile.e0t), Now8 BBBBBBBBBBBBBBBBBBBBBBBBB

+et E@E ?ersion "nformation

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to populate a list"o0 with the e0ecuta"le)s 2ersion in%ormation7 BBBBBBBBBBBBBBBBBBBBBBBBB G Usage7 ?ersion*n%ormation6+ist$o0<8 H GPads or truncates a String and Vusti%ies +e%t i% StrVusti%'=!rueH Function StringPad6 *nputStr, Fill4har7 String9 Str+en7 *nteger9 StrVusti%'7 $oolean87 String9 ?ar !empFill7 String9 4ounter 7 *nteger9 $egin *% Not 6+ength6*nputStr8 = Str+en8 !hen $egin *% +ength6*nputStr8 P Str+en !hen $egin *nputStr 7= 4op'6*nputStr,<,Str+en8 9 -nd -lse $egin !empFill 7= ))9 For 4ounter 7= < !o Str+en;+ength6*nputStr8 Do $egin !empFill 7= !empFill 1 Fill4har9 -nd9 *% StrVusti%' !hen $egin G+e%t Vusti%iedH *nputStr 7= *nputStr 1 !empFill9 -nd -lse $egin G>ight Vusti%iedH *nputStr 7= !empFill 1 *nputStr 9 -nd9 -nd9 -nd9 >esult 7= *nputStr9 -nd9

Function ?ersion*n%ormation6 +ist$o0 7 !+ist$o087 $oolean9 const *n%oNum = <<9 *n%oStr 7 arra' J<..*n%oNumL o% String = 6)4ompan'Name), )FileDescription), )File?ersion), )*nternalName), )+egal4op'right), )+egal!rade3arks), )/riginalFilename), )ProductName), )Product?ersion), )4omments), )&uthor)8 9 +a"elStr 7 arra' J<..*n%oNumL o% String = 6)4ompan' Name), )Description), )File ?ersion), )*nternal Name), )4op'right), )!rade3arks), )/riginal File Name), )Product Name), )Product ?ersion), )4omments), )&uthor)8 9 2ar S 7 String9 n, +en, j 7 *nteger9 $u% 7 P4har9 ?alue 7 P4har9 "egin !r' S 7= &pplication.-0eName9 +ist$o0.*tems.4lear9 +ist$o0.Sorted 7= !rue9 +ist$o0.Font.Name 7= )4ourier New)9 n 7= GetFile?ersion*n%oSiCe6P4har6S8,n8 9 *% n P @ !hen $egin $u% 7= &lloc3em6n8 9 +ist$o0.*tems.&dd 6StringPad6)SiCe),) ),E@,!rue81) = )1*nt!oStr6n88 9 GetFile?ersion*n%o6P4har6S8,@,n,$u%8 9 For j7=< !o *n%oNum Do $egin *% ?er\uer'?alue6$u%,P4har6)StringFile*n%oI@S@Z@S-SI)1 *n%oStrJjL8,Pointer6?alue8,+en8 !hen $egin ?alue 7= P4har6!rim6?alue88 9 *% +ength6?alue8 P @ !hen $egin +ist$o0.*tems.&dd 6StringPad6la"elStr,) ),E@,!rue81) = )1?alue8 9 -nd9 -nd9 -nd9 Free3em6$u%,n8 9 -nd -lse $egin +ist$o0.*tems.&dd 6)No File?ersion*n%o %ound)8 9 -nd9

>esult 7= !rue9 -0cept >esult 7= False9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB

"mplementing a lasso dra'ing techniAue


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s one approach to drawing a lasso rectangle using Delphi7 BBBBBBBBBBBBBBBBBBBBBBBBB <. *n the /n3ouseDown e2ent %or the %orm that 'ou are )lasso;ing) controls on7 "3arAuee 7= !rue9 pt/rigin 7= Point6.,Y8 9 pt3o2e 7= Point6.,Y8 9 Pen.4olor 7= cl$lack9 Pen.#idth 7= <9 Pen.St'le 7= psDash9 $rush.St'le 7= "s4lear9 Draw3arAuee6pt/rigin, pt3o2e, pmNot.or 8 9 E. *n the /n3ouse3o2e e2ent %or the %orm... i% "3arAuee = !rue then "egin Draw3arAuee6pt/rigin, pt3o2e, pmNot.or8 9 Draw3arAuee6pt/rigin, Point6.,Y8, pmNot.or8 9 pt3o2e 7= Point6., Y8 9 4an2as.Pen.3ode 7= pm4op'9 end9 N.*n the /n3ouseUp e2ent %or the %orm... i% "3arAuee = !rue then "egin "3arAuee 7= False9 Draw3arAuee6pt/rigin, Point6.,Y8, pmNot.or8 9 pt3o2e 7= Point6.,Y8 9 end9 S. !he Draw3arAuee procedure...

procedure m'Form.Draw3arAuee 6mStart, mStop 7 !Point9 &3ode 7 !Pen3ode8 9 "egin 4an2as.Pen.3ode 7= &3ode9 4an2as.>ectangle6mStart..,mStart.Y,mStop..,mStop.Y8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

"mplementing Application;Restart
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to create a procedure that will restart the application7 BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&pi9 procedure &pp>estart9 2ar &ppName 7 P4har9 "egin &ppName 7= P4har6&pplication.-0eName8 9 Shell-0ecute6(andle,)open), &ppName, nil, nil, S#,S(/#N/>3&+8 9 &pplication.!erminate9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to set system 'ide Hot 4ey for a Delphi application


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now &n answer to the Auesion7 53' application is minimiCed in the !ra' and * want to know how to code a 5short;cut5 ke', %or e0ample &lt;Shi%t;FZ, to "ring m' application to the top o% the Desktop screen:5 BBBBBBBBBBBBBBBBBBBBBBBBB FF*n the main %orms /n4reate FFhandler assign the hotke'7 *% not >egister(otke' 6(andle, <, 3/D,&+! or 3/D,S(*F!, ?X,FZ8 !hen Show3essage6)Una"le to assign &lt;Shi%t;FZ as hotke'.)8 9

FF*n the main %orms FF/n4lose e2ent remo2e the handler7 Un>egister(otke'6 (andle, < 8 9 FF&dd a handler %or the FF#3,(/!X-Y message to the %orm7 pri2ate FF %orm declaration Procedure #3(otke'6 ?ar msg7 !#3(otke' 8 9 message #3,(/!X-Y9 Procedure !Form<.#3(otke'6 ?ar msg7 !#3(otke' 8 9 $egin *% msg.hotke' = < !hen $egin *% *s*conic6 &pplication.(andle 8 !hen &pplication.>estore9 $ring!oFront9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB

!reate an Auto*Run !D
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his is not a Delphi trick, "ut as a programmer 6using an' language8 some time 'ou might need this7 #hat 'ou ha2e to do is to create a te0t %ile named 5&utorun.*NF5 containing the %ollowing te0t7 JautorunL /P-N=m'program.-.*4/N=m'icon.*4/ where m'program.e0e is the application that 'ou want to 5autorun5 and the icon will "e the icon %or the 4D when 'ou put it in.

"s 5oint in 5olygon6


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his solution checks how man' times 'ou cross a line to pass %rom point .,Y to the edge o% the pol'gon...

BBBBBBBBBBBBBBBBBBBBBBBBB %unction Pt*nPol' 6const Points7 &rra' o% !Point9 .,Y7 *nteger87 $oolean9 2ar 4ount, X, V 7 *nteger9 "egin >esult 7= False9 4ount 7= +ength6Points8 9 V 7= 4ount;<9 %or X 7= @ to 4ount;< do "egin i% 66PointsJXL.Y O=Y8 and 6Y O PointsJVL.Y88 or 66PointsJVL.Y O=Y8 and 6Y O PointsJXL.Y88 then "egin i% 60 O 6PointsJjL.. ; PointsJXL..8 Q 6' ; PointsJXL.Y8 F 6PointsJjL.Y ; PointsJXL.Y8 1 PointsJXL..8 then >esult 7= not >esult9 end9 V 7= X9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-ist De$ices (-5T/ !(. ports/ ;;;)


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing procedure will list all the de2ices on 'our computer. You can then e0tract the com ports and printer ports "' looking %or the )4/3) and )+P!) characters in the list. &dd a 3emo and a $utton and place this code in the /n4lick o% a "utton... BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar istr7 string9 isiCe, j7 dword9 "egin setlength6istr, S@@@8 9 isiCe 7= \uer'DosDe2ice6nil, MistrJ<L, S@@@8 9 %or j 7= < to isiCe do i% istrJjL = W@ then istrJjL 7= W<@9 memo<.lines.4omma!e0t 7= istr9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et system info (free memory/ etc)

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Put a !3emo 63emo<8 and a !$utton 6$utton<8 in 'our %orm. Put this code into /n4lick o% $utton<7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar 3emor'Status7 !3emor'Status9 "egin 3emo<.+ines.4lear9 3emor'Status.dw+ength 7= SiCe/%63emor'Status8 9 Glo"al3emor'Status63emor'Status8 9 with 3emor'Status do "egin 3emo<.+ines.&dd6*nt!oStr6dw+ength8 1 ) SiCe o% ))3emor'Status)) record)8 9 3emo<.+ines.&dd6*nt!oStr6dw3emor'+oad8 1 )[ memor' in use)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otalPh's8 1 ) !otal Ph'sical 3emor' in "'tes)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ailPh's8 1 ) &2aila"le Ph'sical 3emor' in "'tes)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otalPageFile8 1 ) !otal $'tes o% Paging File)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ailPageFile8 1 ) &2aila"le "'tes in paging %ile)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otal?irtual8 1 ) User $'tes o% &ddress space)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ail?irtual8 1 ) &2aila"le User "'tes o% address space)8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et !ursor "mage (dra' it on a !an$as)


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he Draw4ursor procedure draws a current cursor image on &4an2as at the Position point7 BBBBBBBBBBBBBBBBBBBBBBBBB rocedure Draw4ursor 6&4an2as7!4an2as9 Position7!Point8 9 2ar (4ursor 7 !(andle9 "egin (4ursor 7= Screen.4ursors J/rd6Screen.4ursor8L9

Draw*con-06&4an2as.(andle, Position.., Position.Y, (4ursor, NE, NE, @, @, D*,N/>3&+8 9 end9 G Usage 6top;le%t on a %orm<87 Draw4ursor6%orm<.4an2as,Point6@,@88 9 H BBBBBBBBBBBBBBBBBBBBBBBBB

Acti$ate%Deacti$ate the creen a$er


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Sometimes 'ou want to deacti2ate the current screensa2er when per%orming some 2er' long process. You can use this %unction to acti2ate or deacti2ate the screensa2er. Pass !rue to acti2ate it, or False to deacti2ate it. BBBBBBBBBBBBBBBBBBBBBBBBB %unction &cti2ateScreenSa2er 6&cti2ate7 "oolean87 "oolean9 2ar *nt&cti2e7 "'te9 "egin i% &cti2ate then *nt&cti2e 7= < else *nt&cti2e 7= @9 >esult 7= S'stemParameters*n%o 6SP*,S-!S4>--NS&?-&4!*?-, *nt&cti2e, nil, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-ist All 3et'ork Dri$es


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o show a list o% all mapped network dri2es, use the GetNetworkDri2e3appings %unction. -0ample usage7 OpPGetNetworkDri2e3appings63emo<.+ines8 9 BBBBBBBBBBBBBBBBBBBBBBBBB %unction GetNetworkDri2e3appings 6S+ist7 !Strings87 integer9 2ar

i7 4har9 !hePath7 string9 3a0NetPath+en7 D#ord9 "egin S+ist.4lear9 3a0NetPath+en 7= 3&.,P&!(9 Set+ength6!hePath, 3&.,P&!(8 9 %or i 7= )&) to )Z) do i% #NetGet4onnection6P4har6)) 1 i 1 )7)8, P4har6!hePath8, 3a0NetPath+en8 = N/,->>/> then S+ist.&dd6i 1 )7 ) 1 !hePath8 9 >esult 7= S+ist.4ount9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et "E fa$orites


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he Get*-Fa2ourites %unction called %rom the /n4lick e2ent o% a "utton returns a list o% all the %a2orites %rom 'our *nternet -0plorer in a +ist$o0. BBBBBBBBBBBBBBBBBBBBBBBBB %unction Get*-Fa2ourites 6const %a2path7 string87!Strings9 2ar searchrec7!Searchrec9 str7!Strings9 path,dir,%ilename7String9 $u%%er7 arra'[email protected]@SDL o% 4har9 %ound7*nteger9 "egin str7=!String+ist.4reate9 tr' path7=Fa2Path1)IQ.url)9 dir7=-0tractFilepath6path8 9 %ound7=FindFirst6path,%a&n'File,searchrec8 9 while %ound=@ do "egin SetString6%ilename, $u%%er, GetPri2atePro%ileString6)*nternetShortcut), P4har6)U>+)8, N*+, $u%%er, SiCe/%6$u%%er8, P4har6dir1searchrec.Name888 9 str.&dd6%ilename8 9 %ound7=FindNe0t6searchrec8 9 end9 %ound7=FindFirst6dir1)IQ.Q),%a&n'File,searchrec8 9 while %ound=@ do "egin

i% 66searchrec.&ttr and %aDirector'8 P @8 and 6searchrec.NameJ<LOP).)8 then str.&ddStrings6Get*-Fa2ourites 6dir1)I)1searchrec.name88 9 %ound7=FindNe0t6searchrec8 9 end9 Find4lose6searchrec8 9 %inall' >esult7=str9 end9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar pidl7 P*tem*D+ist9 Fa2Path7 arra'[email protected]&.,P&!(L o% char9 "egin S(GetSpecialFolder+ocation6(andle, 4S*D+,F&?/>*!-S, pidl8 9 S(GetPathFrom*D+ist6pidl, %a2path8 9 +ist$o0<.*tems7=Get*-Fa2ourites6StrPas6Fa2Path88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!hange glyphs of TDB3a$igator Buttons


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Form< has a D$Na2igator<. *n the /n4reate e2ent %or the %orm the custom "itmap 6)GoFirst)8 %or the First "utton is loaded %rom the resource. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar i 7 *nteger9 tempGl'ph 7 t$itmap9 "egin tempGl'ph 7=!$itmap.4reate9 tr' tempGl'ph.+oadFrom>esourceName 6(*nstance,)GoFirst)8 9 with D$Na2igator< do "egin %or i 7= @ to 4ontrol4ount ; < do i% 4ontrolsJcL is !Na2igate$tn then with !Na2igate$tn64ontrolsJcL8 do "egin case *nde0 o% n"First7 Gl'ph 7= tempGl'ph9 end9 end9

end9 %inall' tempGl'ph.Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et the Height%&idth of a !haracter (for ('nerDra'ing and printing)


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now #hen using /wnerDrawing or Printing it is good to know the 6ma08 (eight and #idth o% character %or a gi2en 4an2as ; in pi0els. !he Some4omponents represents a component with a 4an2as 6the one deri2ed %rom !#in4ontrol8 BBBBBBBBBBBBBBBBBBBBBBBBB Some4omponent.4an2as.!e0t#idth6)()8 9 Some4omponent.4an2as.!e0t(eight6)*)8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

5aint a Form 'ith a tiled bitmap image


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to draw tiled "itmap image on a Form7 BBBBBBBBBBBBBBBBBBBBBBBBB t'pe !Form< = class6!Form8 procedure Form4reate6Sender7 !/"ject8 9 procedure FormPaint6Sender7 !/"ject8 9 procedure Form4lose6Sender7 !/"ject9 2ar &ction7 !4lose&ction8 9 pri2ate pu"lic end9 2ar Form<7 !Form<9 $itmap7 !$itmap9 ...

procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin $itmap 7= !$itmap.4reate9 $itmap.+oadFromFile6)47I#*ND/#SIcars.$3P)8 9 end9 procedure !Form<.Form4lose 6Sender7 !/"ject9 2ar &ction7 !4lose&ction8 9 "egin $itmap.Free9 end9 procedure !Form<.FormPaint6Sender7 !/"ject8 9 2ar ., Y, #, (7 +ong*nt9 "egin with $itmap do "egin # 7= #idth9 ( 7= (eight9 end9 Y 7= @9 while Y O (eight do "egin . 7= @9 while . O #idth do "egin 4an2as.Draw6., Y, $itmap8 9 *nc6., #8 9 end9 *nc6Y, (8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!on$ert a B.5 to a B5+


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now You can easil' con2ert a $3P image to a VPG 6VP-G8 image7 BBBBBBBBBBBBBBBBBBBBBBBBB G Usage7 $3PtoVPG6)m'"itmap."mp),)m'jpeg.jpg)8 H %unction $3PtoVPG 62ar $3Ppic, VPGpic7 string87"oolean9

2ar $itmap7 !$itmap9 Vpeg*mg7 !Vpeg*mage9 "egin >esult7=False9 $itmap 7= !$itmap.4reate9 tr' $itmap.+oadFromFile6$3Ppic8 9 Vpeg*mg 7= !Vpeg*mage.4reate9 tr' Vpeg*mg.&ssign6$itmap8 9 Vpeg*mg.Sa2e!oFile6VPGpic8 9 >esult7=!rue9 %inall' Vpeg*mg.Free end9 %inall' $itmap.Free end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

a$e te0t from !lipboard to a file


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou want to sa2e the te0t data contained in the 4lip"oard to a te0t %ile on a disk, use the ne0t code7 BBBBBBBBBBBBBBBBBBBBBBBBB G Usage7 4lip"oard!0t!oFile6c7IdirIclipte0t.t0t8 H uses 4lip"rd9 %unction 4lip"oard!0t!oFile 6sFile!.! 7 string8 7 "oolean9 2ar ps<, psE 7 P4har9 dw+en 7 D#ord9 t% 7 !e0tFile9 hData 7 !(andle9 "egin >esult 7= False9 with 4lip"oard do "egin

tr' /pen9 i%6(asFormat64F,!-.!88 then "egin hData 7= Get4lip"oardData64F,!-.!8 9 ps< 7= Glo"al+ock6hData8 9 dw+en 7= Glo"alSiCe6hData8 9 psE 7= Str&lloc6< 1 dw+en8 9 Str+4op'6 psE, ps<, dw+en 8 9 Glo"alUnlock6 hData 8 9 &ssignFile6t%, sFile!.!8 9 >e#rite6t%8 9 #rite6t%, psE8 9 4loseFile6t%8 9 StrDispose6 psE 8 9 >esult 7= !rue9 end9 %inall' 4lose9 end9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!on$ert T!olor to He0 ) He0 to T!olor


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere are two simple %unctions to con2ert color 2alues %rom !4olor to (e0 6(!3+8 and 2ice 2ersa7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction !4olor!o(e064olor 7 !4olor8 7 string9 "egin >esult 7= *nt!o(e06Get>?alue64olor8, E8 1 *nt!o(e06GetG?alue64olor8, E8 1 *nt!o(e06Get$?alue64olor8, E8 9 end9 %unction (e0!o!4olor6s4olor 7 string8 7 !4olor9 "egin >esult 7= >G$6 Str!o*nt6)U)14op'6s4olor, <, E88, Str!o*nt6)U)14op'6s4olor, N, E88,

Str!o*nt6)U)14op'6s4olor, K, E88 89 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!apture the output from a D( (command%console) &indo'


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he e0ample runs )chkdsk.e0e c7I) and displa's the output to 3emo<. Put a !3emo 63emo<8 and a !$utton 6$utton<8 on 'our %orm. Put this code in the /n4+ick e2ent procedure %or $utton<7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 procedure >unDos*n3emo6Dos&pp7String9&3emo7!3emo8 9 const >ead$u%%er = ES@@9 2ar Securit' 7 !Securit'&ttri"utes9 >eadPipe,#ritePipe 7 !(andle9 start 7 !StartUp*n%o9 Process*n%o 7 !Process*n%ormation9 $u%%er 7 Pchar9 $'tes>ead 7 D#ord9 &pprunning 7 D#ord9 "egin #ith Securit' do "egin nlength 7= SiCe/%6!Securit'&ttri"utes8 9 "inherithandle 7= true9 lpsecurit'descriptor 7= nil9 end9 i% 4reatepipe 6>eadPipe, #ritePipe, MSecurit', @8 then "egin $u%%er 7= &lloc3em6>ead$u%%er 1 <8 9 Fill4har6Start,SiCeo%6Start8,W@8 9 start.c" 7= SiCe/%6start8 9 start.hStd/utput 7= #ritePipe9 start.hStd*nput 7= >eadPipe9 start.dwFlags 7= S!&>!F,US-S!D(&ND+-S 1 S!&>!F,US-S(/##*ND/#9 start.wShow#indow 7= S#,(*D-9 i% 4reateProcess6nil,

P4har6Dos&pp8, MSecurit', MSecurit', true, N/>3&+,P>*/>*!Y,4+&SS, nil, nil, start, Process*n%o8 then "egin repeat &pprunning 7= #aitForSingle/"ject 6Process*n%o.hProcess,<@@8 9 &pplication.Process3essages9 until 6&pprunning OP #&*!,!*3-/U!8 9 >epeat $'tes>ead 7= @9 >eadFile6>eadPipe,$u%%erJ@L, >ead$u%%er,$'tes>ead,nil8 9 $u%%erJ$'tes>eadL7= W@9 /em!o&nsi6$u%%er,$u%%er8 9 &3emo.!e0t 7= &3emo.te0t 1 String6$u%%er8 9 until 6$'tes>ead O >ead$u%%er8 9 end9 Free3em6$u%%er8 9 4lose(andle6Process*n%o.hProcess8 9 4lose(andle6Process*n%o.h!hread8 9 4lose(andle6>eadPipe8 9 4lose(andle6#ritePipe8 9 end9 end9 "egin G"utton < codeH >unDos*n3emo6)chkdsk.e0e c7I),3emo<8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!opying group of files * standard animation dialog


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he %ollowing e0ample demonstrates using the S(File/peration %unction to cop' a group o% %iles and displa' a progress dialog. You can also use the %ollowing %lags to delete, mo2e and rename a group o% %iles.

F/,4/PY F/,D-+-!F/,3/?F/,>-N&3Note7 !he "u%%er that contains the %ile names to cop' must end with a dou"le null terminating character !he %ollowing e0ample copies three %iles to )e) dri2e. BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&P*9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar Fos 7 !S(File/pStruct9 $u% 7 arra'[email protected]@ZRL o% char9 p 7 pchar9 sDest 7 string9 "egin Fill4har6$u%, siCeo%6$u%8, W@8 9 p 7= M"u%9 p 7= Str-4op'6p, )47IFirstFile.e0t<)8 1 <9 p 7= Str-4op'6p, )47ISecondFile.e0tE)8 1 <9 Str-4op'6p, )47I!hirdFile.e0tN)8 9 sDest 7= )e7I)9 Fill4har6Fos, siCeo%6Fos8, W@8 9 with Fos do "egin #nd 7= (andle9 wFunc 7= F/,4/PY9 pFrom 7= M$u%9 p!o 7= sDest9 %Flags 7= @9 end9 i% 66S(File/peration6Fos8 OP @8 or 6Fos.%&n'/perations&"orted OP %alse88 then Show3essage6)4ancelled)8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

-ong -istBo0 entries as hints


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now

Sometimes the data 'ou want to displa' in a list is too long %or the siCe o% +ist$o0 'ou can use. #hen this happens, 'ou can use the simple code to displa' the +ist$o0 entries as (ints when the mouse passes o2er the +ist$o0. Vust make sure that Show(ints is !rue. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.+ist$o0<3ouse3o2e 6Sender7 !/"ject9 Shi%t7 !Shi%tState9 ., Y7 *nteger8 9 2ar lst*nde0 7 *nteger 9 "egin with +ist$o0< do "egin lst*nde07=Send3essage6(andle, +$,*!-3F>/3P/*N!, @, 3ake+Param60,'88 9 i% 6lst*nde0 P= @8 and 6lst*nde0 O= *tems.4ount8 !hen (int 7= *temsJlst*nde0L else (int 7= )) end9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB

Add a !heck Bo0 to a standard dialog bo0


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now For e0ample, we ha2e some dialog %or con%irmation and the user can check a check"o0 65Don)t show this message again58 ; program can store this in a glo"al 2aria"le and the ne0t time this dialog will not show. !he idea o% realiCation in the ne0t7 <. we must create a dialog using 4reate3essageDialog E. this %unction will return a %orm o"ject with dialog N. in this o"ject we can add a check"o0 S. show diallog using Show3odal K. check a result and process a state o% our check"o0 R. destro' a created check"o0 and dialog o"ject BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar &3sgDialog7 !Form9 &4heck$o07 !4heck$o09 "egin &3sgDialog 7= 4reate3essageDialog 6)!his is a test message.), mt#arning, Jm"Yes, m"NoL8 9

&4heck$o0 7= !4heck$o0.4reate6&3sgDialog8 9 with &3sgDialog do tr' 4aption 7= )Dialog !itle) 9 (eight 7= <RZ9 with &4heck$o0 do "egin Parent 7= &3sgDialog9 4aption 7= )Don))t show me again.)9 !op 7= <E<9 +e%t 7= Y9 end9 i% 6Show3odal = *D,Y-S8 then "egin i% &4heck$o0.4hecked then "egin FF... do i% checked end9 FF... do i% N/! checked end9 %inall' Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

+et .emory tatus


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o retrie2e the current memor' status, use the Glo"al3emor'Status68 %unction. !he !3emor'Status contains se2eral %ields indicating the status o% the memor'7 .dw3emor'+oad7 !otal memor' used in percentage 6[8 . .dw!otalPh's7 !otal ph'sical memor' in "'tes. .dw&2ailPh's7 Ph'sical memor' le%t in "'tes. .dw!otalPageFile7 !otal page %ile in "'tes. .dw&2ailPageFile7Page %ile le%t in "'tes. .dw!otal?irtual7 !otal 2irtual memor' in "'tes. .dw&2ail?irtual7 ?irtual memor' le%t in "'tes. $e%ore presenting the memor' 2alues, con2ert them into giga, mega or kilo"'tes. BBBBBBBBBBBBBBBBBBBBBBBBB 2ar

Status 7 !3emor'Status9 "egin Status.dw+ength 7= siCeo%6 !3emor'Status 8 9 Glo"al3emor'Status6 Status 8 9 ... BBBBBBBBBBBBBBBBBBBBBBBBB

E0it From &indo's


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to e0it %rom #indows using Delphi and &P* 7 BBBBBBBBBBBBBBBBBBBBBBBBB FFre"oot windows -0it#indows-06-#.,>-$//!,@8 9 FFshut down windows -0it#indows-06-#.,S(U!D/#N,@8 9 FF log o%% and prompt %or login -0it#indows-06-#.,+/G/FF,@8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

Empty Recycle Bin


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Put a $utton on Form< and replace Unit< code the %ollowing code7 BBBBBBBBBBBBBBBBBBBBBBBBB unit Unit<9 inter%ace uses #indows, 3essages, S'sUtils, 4lasses, Graphics, Shell&pi,4ontrols, Forms, Dialogs,Std4trls, -0t4trls9 t'pe !Form< = class6!Form8 $utton<7 !$utton9 procedure $utton<4lick6Sender7 !/"ject8 9 end9 2ar Form<7 !Form<9 %unction S(-mpt'>ec'cle$in 6#nd7(#nd9 +P4!S!>7P4har9 D#/>D7#ord87*nteger9 stdcall9

const S(->$,N/4/NF*>3&!*/N = U@@@@@@@<9 S(->$,N/P>/G>-SSU* = U@@@@@@@E9 S(->$,N/S/UND = U@@@@@@@S9 implementation GU> Q.DF3H %unction S(-mpt'>ec'cle$in9 e0ternal )S(-++NE.D++) name )S(-mpt'>ec'cle$in&)9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin S(-mpt'>ec'cle$in6sel%.handle,)), S(->$,N/4/NF*>3&!*/N8 9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB

Be notified8 !D in%out
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to "e noti%ied when 4D drawer is opened or closed7 BBBBBBBBBBBBBBBBBBBBBBBBB GPut this line into pri2ate section o% 'our %orm)s declarationH procedure #3De2ice4hange62ar 3sg7 !3essage8 9 message #3,D-?*4-4(&NG-9 Gthe implementation part7H procedure !Form<.#3De2ice4hange 62ar 3sg7 !3essage8 9 const 4D,*N = UY@@@9 4D,/U! = UY@@S9 2ar 3sg 7 String9 "egin inherited9 case 3sg.wParam o% 4D,*N 7 3sg 7= )4D in)9 4D,/U! 7 3sg 7= )4D out)9 end9 Show3essage63sg8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to get DB+rid !ell coordinates


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he code to show o2er what cell in a D$Grid the cursor is, and how to change the cursor o2er the tite "ar7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Grid3ouse3o2e 6Sender7 !/"ject9 Shi%t7 !Shi%tState9 ., Y7 *nteger8 9 2ar pt7 !Gridcoord9 "egin pt7= Grid.3ouse4oord6 0, ' 8 9 FFchange the cursor whe o2er title i% pt.'=@ then Grid.4ursor7=cr(andPoint else Grid.4ursor7=crDe%ault9 *% pt.. P @ !hen 4aption 7= Format6 )col7 [d, row7 [d, title7 [s), Jpt.0, pt.', Grid.columnsJpt.0;<L.title.captionL 8 -lse 4aption 7= Format6 )col7 [d, row7 [d),Jpt.0, pt.'L 8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Retrie$ing a list of installed Applications on &indo's


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere is a method %or retrie2ing a list o% installed applications on a particular machine running a #indows /S. <. Start up Delphi. E. Select File ^ New &pplication. N. &dd >egistr' to the uses o% 'our new Unit. S. Place a !+ist$o0 6+ist$o0<8 component on 'our %orm. K. Place a !$utton 6$utton<8 in 'our %orm. R. Place the %ollowing code in the /n4lick e2ent o% the $utton<7

BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 const >-GX-Y&PPS = )IS/F!#&>-I3icroso%tI#indowsI 4urrent?ersionIUninstall)9 2ar reg 7 !>egistr'9 +ist< 7 !String+ist9 +istE 7 !String+ist9 j, n 7 integer9 "egin reg 7= !>egistr'.4reate9 +ist< 7= !String+ist.4reate9 +istE 7= !String+ist.4reate9 G+oad all the su"ke'sH with reg do "egin >ootXe' 7= (X-Y,+/4&+,3&4(*N-9 /penXe'6>-GX-Y&PPS, %alse8 9 GetXe'Names6+ist<8 9 end9 G+oad all the ?alue NamesH %or j 7= @ to +ist<.4ount ;< do "egin reg./penXe'6>-GX-Y&PPS 1 )) 1 +ist<.StringsJjL,%alse8 9 reg.Get?alueNames6+istE8 9 G#e will show onl' i% there is )Displa'Name)H n 7= +istE.*nde0/%6)Displa'Name)8 9 i% 6n OP ;<8 and 6+istE.*nde0/%6)UninstallString)8 OP ;<8 then "egin +ist$o0<.*tems.&dd6 6reg.>eadString6+istE.StringsJnL888 9 end9 end9 +ist.Free9 +istE.Free9 reg.4loseXe'9 reg.Destro'9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to get the number of 'ords in Richedit

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s a code to retrie2e the num"er or words in a >ich-dit component7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction Get*s#ord7 "oolean9 2ar s7 string9 Gpresume no wordPEKK charsH c7 char9 "egin result7= %alse9 s7= ) )9 while not eo%6%8 do "egin read6%, c8 9 i% not 6c in J)a)..)C),)&)..)Z)G,... etcHL8 then "reak9 s7=s1c9 end9 result7= 6s OP) )8 9 end9 procedure Get#ord4ount6!e0tFile7 string8 9 "egin 4ount7= @9 assign%ile6%, !e0tFile8 9 reset6%8 9 while not eo%6%8 do i% Get*s#ord then inc64ount8 9 close%ile6%8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to detect 'hen a T.edia5layer stops playing


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he Noti%' propert' resets "ack to False when a noti%' e2ent is triggered, so in order %or 'ou to recie2e %urther noti%' e2ents, 'ou ha2e to set it "ack to !rue as in the code. %or the 3/D-S a2aila"le, see the help%ile %or 3ediaPla'er.3ode. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin 3ediaPla'er<.Noti%' 7= !rue9 3ediaPla'er<./nNoti%' 7= Noti%'Proc9

end9 procedure !Form<.Noti%'Proc6Sender7 !/"ject8 9 "egin with Sender as !3ediaPla'er do "egin case 3ode o% mpStopped7 GD/ something (->-H9 end9 FFmust set to true to FFena"le ne0t;time noti%ication Noti%' 7= !rue9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

!onnect and disconnect to%from the "nternet


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to connect to the *nternet %rom Delphi code7 *nternet&utoDial6dwFlags, hwndParent8 9 #here dwFlags can "e one o% the %ollowing 2alues7 *N!->N-!,&U!/D*&+,F&*+*FS-4U>*!Y4(-4X ; causes *nternet&utodial to %ail i% %ile and printer sharing is disa"led %or 3icroso%t_ #indows_ ZK or later. *N!->N-!,&U!/D*&+,F/>4-,/N+*N- ; %orces an online *nternet connection. *N!->N-!,&U!/D*&+,F/>4-,UN&!!-ND-D ; %orces an unattended *nternet dial;up. and, hwndParent is (andle to the parent window. -0maple7 BBBBBBBBBBBBBBBBBBBBBBBBB uses #in*net9 ... *nternet&utoDial6internet,autodial,%orce,unattended, (andle8 9 G !o disconnect this automatic dial;up connection, use H *nternet&utodial(angup6@8 G &nother wa' is to speci%' the name

o% the connection 'ou wish to use 64onnectionName8, %rom Dialup networking7 H i% *nternetDial 6@, P4har64onnectionName8, *N!->N-!,&U!/D*&+,F/>4-,UN&!!-ND-D, dw4onn, @8 OP ->>/>,SU44-SS then e0it9 FFDo something with *nternet... *nternet(angup6dw4onn, @8 9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to correctly use the mouse 'heel in TDB+rid


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 3ouse wheel "eha2es strangel' with d"grids ; this code handler will correct this "eha2ior. Vust drop a !&pplication-2ents 65&dditional5 ta" on the 4omponent Palette8 component on a %orm and handle it)s /n3essage e2ent as7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.&pplication-2ents<3essage 62ar 3sg7 !3sg9 2ar (andled7 $oolean8 9 2ar i7 Small*nt9 "egin i% 3sg.message = #3,3/US-#(--+ then "egin 3sg.message 7= #3,X-YD/#N9 3sg.lParam 7= @9 i 7= (i#ord63sg.wParam8 9 i% i P @ then 3sg.wParam 7= ?X,UP else 3sg.wParam 7= ?X,D/#N9 (andled 7= False9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB Note7 !his %i0es the mouse wheel "eha2ior not onl' %or D$Grid;s "ut %or all other list component 6!+ist$o0, !+ist?iew, etc8.

Ho' to split a string into an array


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now & simple %unction that accepts a string and a delimiter char, splits a string into tokens 6!String+ist items8 delimited with a char 2alue. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar &7 !String+ist9 "egin & 7= !String+ist.4reate9 tr' Split6) ), )'our delphi guide), &8 9 Show3essage6aJ@L8 9 FF'our Show3essage6aJ<L8 9 FFdelphi Show3essage6aJEL8 9 FFguide %inall' &.Free9 end9 end9 H procedure Split 6const Delimiter7 4har9 *nput7 string9 const Strings7 !Strings8 9 "egin &ssert6&ssigned6Strings88 9 Strings.4lear9 Strings.Delimiter 7= Delimiter9 Strings.Delimited!e0t 7= *nput9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Adding an icon to the standard &indo's About dialog


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou want to "ring up the standard #indows )&"out..) dialog "o0, then 'ou can use Shell&"out68 %rom the Shell&P* unit and customiCe the appearance "' adding 'our own te0t, application name and an icon.

!he downside to this techniAue is that it will sa' )6c8 3icroso%t) in the "o0. !he upside is that 'ou see the registered user and some s'stem parameters 6%ree space..8. *t)s a Auick;and;dirt' solution %or an &"out;"o0. BBBBBBBBBBBBBBBBBBBBBBBBB uses #indows, Shell&P*9 procedure !Form<.&"out<4lick6Sender7 !/"ject8 9 "egin Shell&"out6&pplication.3ainForm.(andle, )3' great Delphi application), )?ersion E@@E)W<NW<@1 )4ompiled E@@<;@Y;@N <K7EK7<@), &pplication.*con.(andle8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to store a TDateTime in the Registry


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 4on2erting it to a string and then "ack is not alwa's satis%actor' as people can change their date and time %ormats and we do not want to impose an' restrictions on the so%tware. !Date!ime is a %loat, so we can store it as a "inar' 2alue. BBBBBBBBBBBBBBBBBBBBBBBBB program Date>egistr'9 uses #indows, Dialogs, >egistr', S'sUtils9 GU> Q.>-SH procedure Sa2eDate 6const sXe'7 string9 const sField7 string9 aDate7 !Date!ime8 9 "egin with !>egistr'.4reate do "egin >ootXe' 7= (X-Y,4U>>-N!,US->9 i% /penXe'6sXe', !rue8 then

"egin #rite$inar'Data6sField, aDate, SiCe/%6aDate88 9 4loseXe'9 end9 Free9 end9 end9 %unction >eadDate 6const sXe'7 string9 const sField7 string8 7 !Date!ime9 "egin FF de%ault7 return @ >esult 7= @9 with !>egistr'.4reate do "egin >ootXe' 7= (X-Y,4U>>-N!,US->9 i% /penXe'6sXe', False8 then "egin tr' >ead$inar'Data6sField, >esult, SiCe/%6>esult88 9 e0cept end9 4loseXe'9 end9 Free9 end9 end9 2ar dDate7 !Date!ime9 "egin FF sa2e the date Sa2eDate6)IDate!imeDemo), )+astDate), Now8 9 FF retrie2e it dDate 7= >eadDate6)IDate!imeDemo), )+astDate)8 9 FF show it Show3essage6Date!ime!oStr6dDate88 9 end. BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to !on$ert a tring of "ntegers into an Array of Byte

From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he "est solution is to d'namicall' create an arra' o% "'te that has length eAual to that o% the string. /nce 'ou ha2e 'our arra' 'ou can %ill the arra' with the 2alues %rom the string, howe2er there is some o%%set since the ascii representation o% the character )<) isn)t eAui2alent to <. $elow is a sample o% how one might return an arra' o% "'te7 BBBBBBBBBBBBBBBBBBBBBBBBB inter%ace uses ... t'pe FFd'namic arra' t'pe %or &rra' o% $'te !$'te&rr = arra' o% "'te9 ... implementation %unction &rr/%$'te6&Str7 String87 !$'te&rr9 2ar j7 integer9 "egin Set+ength6 >esult, +ength6&Str88 9 %or j 7= @ to +ength6&Str8 ; < do >esultJjL 7= ord6&StrJj 1 <L8 ; SY9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Delphi plit % Tokeni2er functions


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now BBBBBBBBBBBBBBBBBBBBBBBBB unit SplitFns9 inter%ace uses 4lasses9 %unction GetNe0t!oken 64onst S7 string9 Separator7 char9 2ar StartPos7 integer87 String9 G>eturns the ne0t token 6su"string8 %rom string S, starting at inde0 StartPos and ending < character "e%ore the ne0t occurrence o%

Separator 6or at the end o% S, whiche2er comes %irst8.H GStartPos returns the starting position %or the ne0t token, < more than the position in S o% the end o% this tokenH procedure Split 6const S7 String9 Separator7 4har9 3'String+ist7 !String+ist8 9 GSplits a string containing designated separators into tokens and adds them to 3'String+ist N/!-7 3'String+ist must "e 4reated "e%ore "eing passed to this procedure and Freed a%ter useH %unction &dd!oken 6const a!oken, S7 String9 Separator7 4har9 String+imit7 integer87 String9 GUsed to join E strings with a separator character "etween them and can "e used in a Voin %unctionH G!he String+imit parameter pre2ents the length o% the >esult String %rom e0ceeding a preset ma0imumH implementation Uses S'sutils9 %unction GetNe0t!oken 64onst S7 string9 Separator7 char9 2ar StartPos7 integer87 String9 2ar *nde07 integer9 "egin >esult 7= ))9 GStep o2er repeated separatorsH #hile 6SJStartPosL = Separator8 and 6StartPos O= length6S88do StartPos 7= StartPos 1 <9 i% StartPos P length6S8 then -0it9 GSet *nde0 to StartPosH *nde0 7= StartPos9

GFind the ne0t SeparatorH #hile 6SJ*nde0L OP Separator8 and 6*nde0 O= length6S88do *nde0 7= *nde0 1 <9 G4op' the token to the >esultH >esult 7= 4op'6S, StartPos, *nde0 ; StartPos8 9 GSetStartPos to ne0t 4haracter a%ter the SeparatorH StartPos 7= *nde0 1 <9 end9 procedure Split 6const S7 String9 Separator7 4har9 3'String+ist7 !String+ist8 9 2ar Start7 integer9 "egin Start 7= <9 #hile Start O= +ength6S8 do 3'String+ist.&dd 6GetNe0t!oken6S, Separator, Start88 9 end9 %unction &dd!oken 6const a!oken, S7 String9 Separator7 4har9 String+imit7 integer87 String9 "egin i% +ength6a!oken8 1 +ength6S8 O String+imit then "egin G&dd a separator unless the >esult string is empt'H i% S = )) then >esult 7= )) else >esult 7= S 1 Separator9 G&dd the tokenH >esult 7= >esult 1 a!oken9 end else Gi% the String+imit would "e e0ceeded, raise an e0ceptionH >aise -0ception.4reate6)4annot add token)8 9 end9 end.

C plitFnsD EEEEEEEEEEEEEEEEEEEEEEEEE Ho' to translate a $irtual*key to A !"" code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to get the character %rom the 2irtual ke'7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction Get4harFrom?Xe'62ke'7 #ord87 string9 2ar ke'state7 !Xe'"oardState9 retcode7 *nteger9 "egin #inNE4heck6GetXe'"oardState6ke'state88 9 Set+ength6>esult, E8 9 retcode 7= !o&scii62ke', 3ap?irtualXe'62ke', @8, ke'state, M>esultJ<L, @8 9 case retcode o% @7 >esult 7= ))9 <7 Set+ength6>esult, <8 9 E7 9 else >esult 7= ))9 end9 end9 G Usage7 procedure !Form<.-dit<Xe'Down 6Sender7 !/"ject9 2ar Xe'7 #ord9 Shi%t7 !Shi%tState8 9 "egin Show3essage6Get4harFrom?Xe'6Xe'88 9 end9 H BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to place a T!heckBo0 inside a TRichEdit


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now For the %ollowing e0ample, create a new %orm, drop a !>ich-dit 6>ich-dit<8 on it and create the check"o0 6ac"8 in the Form4reate68 e2ent. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar &c"7 !4heck$o09 "egin >ich-dit<.+e%t 7= E@9 &c" 7= !4heck$o0.4reate6>ich-dit<8 9 &c".+e%t 7= N@9 &c".!op 7= N@9 &c".4aption 7= )m' check"o0)9 &c".Parent 7= >ich-dit<9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB

Ho' to comment out large amount of source code


From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o comment a simple line o% code 'ou could use FF "e%ore that line. !o comment %ew lines 'ou could use G H or 6Q Q8. $ut, i% 'ou ha2e a large amount o% code that 'ou want to comment out, none o% the a"o2e operators ma' help, depending on whether 'ou ha2e alread' used those operators in the code. (ere)s a de%initi2e wa' to comment out code7 GU*FD-F FalseH 'our commented code goes here GU-ND*FH

http7FFdelphi.a"out.comFodF"eginnersFlF"lrtlmain.htm http7FFdelphi.a"out.comFodFwindowsshellapiF http7FFdelphi.a"out.comFF

You might also like