Mega Code Archive

 
Categories / Delphi / Forms
 

Get Application information

Title: Get Application information Question: Get the IDE defined data for your application Answer: As you will know, all this data can be defined in the Delphi's IDEi, in: Project - Options - VersionInfo This article will allow us to obtain the rest of data that it can be defined: Description of the file, internal Name, Company, etc... The biggest complication is the one of knowing how to obtain the information by means of the API function: VerQueryValue, since is to make it in two phases: First, we should obtain a hexadecimal number that corresponds to the ' languaje-character definition' that, it is dependent of the language in that have compiled the application. Once we have this fact, we will be able to request the rest of the information. In the following example, we request the description of the application: procedure TForm1.Button1Click(Sender: TObject); function GetAppInfo(De:string):string; {Se pueden pedir los siguientes datos: We can request the following data: CompanyName FileDescription FileVersion InternalName LegalCopyright OriginalFilename ProductName ProductVersion } type PaLeerBuffer = array [0..MAX_PATH] of char; var Size, Size2 : DWord; Pt, Pt2 : Pointer; Idioma : string; begin Result:=''; Size := GetFileVersionInfoSize(PChar (Application.Exename), Size2); if Size 0 then begin GetMem (Pt, Size); GetFileVersionInfo (PChar (ParamStr (0)), 0, Size, Pt); {Obtenemos la cadena de translacion, requerida para obtener el resto de datos del Versioninfo} {Get the translation string, required to get the rest of the data from the VersionInfo} VerQueryValue( Pt, '\VarFileInfo\Translation',Pt2, Size2); Idioma:=IntToHex( DWord(Pt2^) ,8 ); {Le damos la vuelta (Es windows, que quieres...} {We turn it round (It's Windows, what do you expect?) Idioma:=Copy(Idioma,5,4)+Copy(Idioma,1,4); {Pedimos la info requerida...} {We request the required info...} VerQueryValue( Pt, Pchar('\StringFileInfo\'+ Idioma+'\'+ De), Pt2, Size2); if Size2 0 then begin {Y la devolvemos} {And we give it back} Result:=Copy(PaLeerBuffer(Pt2^),1,Size2); end else raise Exception.Create( 'No existe esa informacion en este ejecutable'+ #13+ 'There are not this info in this executable'); FreeMem (Pt); end else raise exception.Create ( 'Lo siento, no hay VersionInfo disponible '+ 'en este ejecutable.'+#13+ 'Sorry there are not VersionInfo available'+ 'in this executable.'); end; begin Form1.Caption:=Form1.Caption+' '+ GetAppInfo('FileDescription'); end;