Tips&Tricks | I trucchi del mestiere |
![]() |
Come leggere lo stato del CAPS LOCK |
function IsCapsLockOn : boolean; begin Result := 0 <> (GetKeyState(VK_CAPITAL) and $01); end; |
![]() |
Come spostare il focus all'oggetto successivo o precedente |
SelectNext(ActiveControl as TWinControl,True,True ); |
SelectNext(ActiveControl as TWinControl,False,True ); |
![]() |
Come ricavare il nome della window posizionata in una specifica posizione dello schermo |
function NomeWindow( X, Y : integer ) : string; var P : TPoint; W : TWinControl; begin P.X := X; P.Y := Y; W := FindVCLWindow( P ); if( nil <> W )then begin Result := W.Name; end else begin Result := ''; end; end; |
![]() |
Come mappare l'hard-disk |
DWORD WNetAddConnection2( LPNETRESOURCE lpNetResource, LPCTSTR lpPassword, LPCTSTR lpUsername, DWORD dwFlags ); Function MappaDischi(LocalUnit, UserN, PassW: String): boolean; var NRW: NetResource; Res: DWORD; begin Result := False; NRW.dwType := RESOURCETYPE_DISK; NRW.lpLocalName := PChar(LocalUnit + ':'); NRW.lpRemoteName := PChar('\\indirizzoIP\D$'); NRW.lpProvider := ''; Res = WNetAddConnection2(NRW, PChar(PassW), PChar(UserN), CONNECT_UPDATE_PROFILE) Result := (Res <> NO_ERROR) If Not Result Then ShowMessage('Non Φ possibile eseguire la mappatura); end; |
![]() |
Come leggere la data dell'ultimo accesso ad un file |
function Ultimoaccesso(sFileName : string ) : TDateTime; var ffd : TWin32FindData; dft : DWord; lft : TFileTime; h : THandle; begin h := Windows.FindFirstFile(PChar(sFileName), ffd); if (INVALID_HANDLE_VALUE <> h) then begin Windows.FindClose( h ); FileTimeToLocalFileTime(ffd.ftLastAccessTime, lft ); FileTimeToDosDateTime(lft,LongRec(dft).Hi, LongRec(dft).Lo); Result := FileDateToDateTime(dft); end; end; |
![]() |
Come chiedere conferma per la chiusura di una applicazione |
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if(mrNo = MessageDlg('Sei sicuro di voler terminare il programma?'', mtInformation,[mbYes, mbNo],0)) then begin CanClose := False; end; end; |
![]() |
Aprire e chiudere il carrello del lettore del CD |
Procedure ApriCD; Begin mciSendString('Set cdaudio door open', nil, 0, 0); End; Procedure ChiudiCD; Begin mciSendString('Set cdaudio door closed', nil, 0, 0); End; |
![]() |
Inviare una e-mail con il programma di posta elettronica predefinito |
ShellExecute(Handle, 'open', 'mailto: GiuseppeSgro@email.it?subject=mail', '', '', SW_SHOWDEFAULT); |
![]() |
Lanciare il browser predefinito ed aprire una pagina web |
ShellExecute(Handle, 'open', 'http://www.delphitips.com', '', '', SW_SHOWDEFAULT); |
![]() |
Come convertire un carattere nel suo corrispondente codice ascii |
Label1.Caption:='Il codice ASCII del carattere "A" Φ ' + IntToStr(ord('A')); Label2.Caption:='Il carattere corripondente al codice ASCII 65 Φ' + chr(65); |
![]() |
Lanciare un'applicazione ed attenderne la fine dell'esecuzione |
procedure Esempio; var ProgramHandle : THandle; begin ProgramHandle := WinExec('C:\Programma.exe', SW_SHOWNORMAL); while GetModuleusage(ProgramHandle) <> 0 do application.processmessages; {Tutto ci≥ che verrα iserito qui sarα eseguito finchΦ non termina l'applicaizone esegiuta da winexec} end; |