Tehnika Krstarice > Programiranje > Delphi - Iščitavanje informacija o programu

Delphi - Iščitavanje informacija o programu

05.08.2001.

Delphi svojim korisnicima - programerima, omogućava da uz svaki projekat (aplikaciju) smeste i osnovne informacije o programu, kao što su:

  • Naziv programa
  • Verzija programa
  • Opis projekta
  • Podaci o pravima korišćenja programa
  • Komentari, itd.

Sve ove informacije možete uneti pri kreiranju aplikacija, preko menija "Project> Options" i kartice "Version Info". Ovde unete informacije koriste i samim programerima, ali i budućim korisnicima. Programerima, ponajviše zbog beleženja izmena, revizija, i prepravki u kodu, tj. radi boljeg snalaženja unutar jednog projekta. Korisnicima ova opcija može biti važna, kako zbog praćenja verzije programa kojeg koriste (u sklopu održavanja softverskog proizvoda), tako i zbog prava i obaveza preuzetih kupovinom nekog programa (sekcije "LegalCopyright" i "LegalTrademarks").

Za iščitavanje "VersionInfo" informacija služi procedura "GetFileVersionInfo". U sledećim redovima videćemo primer procedure koja će da iščita sve dostupne VersionInfo informacije i da ih smesti u jedan listbox. Na praznu formu postavite jedno dugme i jednu listu (listbox). Klikom na dugme pozivaćemo funkciju koja će sve odraditi:

 procedure TForm1.Button1Click(Sender: TObject);
 begin
 InformacijeOVerziji(ListBox1);
 end;

Preostali deo koda smestite u isti Unit:

 Function StringPad(
   InputStr,
   FillChar: String;
   StrLen: Integer;
   StrJustify: Boolean): String;
 Var
   TempFill: String;
   Counter : Integer;
 Begin
   If Not (Length(InputStr) = StrLen) Then
   Begin
     If Length(InputStr) > StrLen Then
     Begin
       InputStr := Copy(InputStr,1,StrLen);
     End
       Else
     Begin
       TempFill := '';
       For Counter := 1 To StrLen-Length(InputStr) Do
       Begin
         TempFill := TempFill + FillChar;
       End;
       If StrJustify Then
       Begin
         {Left Justified}
         InputStr := InputStr + TempFill;
       End
         Else
       Begin
         {Right Justified}
         InputStr := TempFill + InputStr ;
       End;
     End;
   End;
   Result := InputStr;
 End;


 Function InformacijeOVerziji(
   ListBox : TListBox): Boolean;
 const
   InfoNum = 11;
   InfoStr : array [1..InfoNum] of String =
     ('CompanyName', 'FileDescription', 'FileVersion',
 	 'InternalName', 'LegalCopyright', 'LegalTradeMarks',
 	 'OriginalFilename', 'ProductName', 'ProductVersion',
 	 'Comments', 'Author');
   LabelStr : array [1..InfoNum] of String =
     ('Company Name', 'Description', 'File Version',
 	 'Internal Name', 'Copyright', 'TradeMarks',
 	 'Original File Name', 'Product Name',
   	 'Product Version', 'Comments', 'Author');
 var
   S: String;
   n, Len, i : Integer;
   Buf : PChar;
   Value : PChar;
 begin
   Try
     S := Application.ExeName;
     ListBox.Items.Clear;
     ListBox.Sorted := True;
     ListBox.Font.Name := 'Courier New';
     n := GetFileVersionInfoSize(PChar(S),n);
     If n > 0 Then Begin
       Buf := AllocMem(n);
       ListBox.Items.Add
 	    (StringPad('Size',' ',20,True)+' = '+IntToStr(n));
       GetFileVersionInfo(PChar(S),0,n,Buf);
       For i:=1 To InfoNum Do Begin
         If VerQueryValue(Buf,PChar('StringFileInfo\040904E4\'+
                   InfoStr[i]),Pointer(Value),Len) Then
         Begin
           Value := PChar(Trim(Value));
           If Length(Value) > 0 Then
           Begin
             ListBox.Items.Add
	 (StringPad(labelStr[i],' ',20,True)+' = '+Value);
           End;
         End;
       End;
       FreeMem(Buf,n);
     End
        Else 
     Begin
       ListBox.Items.Add
             ('Nema FileVersionInfo podataka');
     End;
    Result := True;
  Except
    Result := False;
   End;
 End;

Preporučite ovaj članak

Članak još uvek nije ocenjen.