Forum > Third party
Application Info class
munair:
A simple but handy class for maintaining application info, including directories.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit uApp; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type TApp = class private function _GetDirectory(const global: boolean = false): string; function _GetVendorDirectory(const global: boolean = false): string; public Authors: string; BuildNumber: integer; CopyrightInfo: string; Directory: string; GlobalDirectory: string; GlobalVendorDirectory: string; MajorVersion: integer; MinorVersion: integer; Name: string; RevisionNumber: integer; PackageInfo: string; Title: string; Vendor: string; VendorDirectory: string; function GetDirectories(): boolean; function LongVersion(): string; function ShortVersion(): string; end; procedure UseApp(); var App: TApp; implementation function _GetName(): string;begin result := StringReplace(App.Name, chr(32), chr(45), [rfReplaceAll]);end; function _GetVendor(): string;begin result := StringReplace(App.Vendor, chr(32), chr(45), [rfReplaceAll]);end; procedure UseApp();begin // instantiate App := TApp.Create; // setup handlers OnGetApplicationName := @_GetName; OnGetVendorName := @_GetVendor;end; function TApp.GetDirectories(): boolean;begin try // local directories Directory := _GetDirectory(); VendorDirectory := _GetVendorDirectory(); // global directories GlobalDirectory := _GetDirectory(true); GlobalVendorDirectory := _GetVendorDirectory(true); except exit(false); end; exit(true);end; function TApp._GetDirectory(const global: boolean = false): string;// _GetDirectory and _GetVendorDirectory return the same value if:// - Name and VendorName are not specified// - either Name or VendorName is not specifiedvar dir: string;begin dir := GetAppConfigDir(global); result := lowercase(dir);end; function TApp.LongVersion(): string;begin result := IntToStr(MajorVersion) + '.' + IntToStr(MinorVersion) + '.' + IntToStr(RevisionNumber) + ' build ' + IntToStr(BuildNumber);end; function TApp.ShortVersion(): string;begin result := IntToStr(MajorVersion) + '.' + IntToStr(MinorVersion) + '.' + IntToStr(RevisionNumber);end; function TApp._GetVendorDirectory(const global: boolean = false): string;// _GetDirectory and _GetVendorDirectory return the same value if:// - Name and VendorName are not specified// - either Name or VendorName is not specifiedvar d: string; l: integer;begin d := GetAppConfigDir(global); if Length(Vendor) > 0 then begin l := Length(Name); if l > 0 then begin d := Copy(d, 1, Length(d) - l - 1); end; end; result := lowercase(d);end; end.
See attachement for example project.
eny:
Better do a lot more testing m80:
--- Code: ---var s: string;
....
s := '1';
ReplaceAll(s, '1', '1')
--- End code ---
munair:
--- Quote from: eny on April 09, 2015, 10:52:09 am ---Better do a lot more testing m80:
--- Code: ---var s: string;
....
s := '1';
ReplaceAll(s, '1', '1')
--- End code ---
--- End quote ---
We are living in a open source world mister envy. If you encounter any problem you may want
to figure out for yourself how to improve it and present your solution.
edit: source code updated.
eny:
--- Quote from: Artie on April 09, 2015, 07:40:49 am ---Release the mouse button...
--- End quote ---
munair:
--- Quote from: eny on April 10, 2015, 10:23:19 am ---
--- Quote from: Artie on April 09, 2015, 07:40:49 am ---Release the mouse button...
--- End quote ---
--- End quote ---
That was a solution before he became more specific...
Navigation
[0] Message Index
[#] Next page