Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

ATLibrary

Delphi Auxiliary Toolkit

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Delphi Auxiliary Toolkit

A set of units for delphi and FPC(Most units support), the purposes is to simplify development, it should supports delphi7 and above(tested in D7, TD, XE2, XE5, XE7, D10, D10.1, D10.2, D10.3, D10.4, D11) and platforms Windows(XP or later) and Android(MacOS and iOS not tested), when use FPC, it should supports many platforms and architectures such as Win, Linux|X86/X64, arm/aarch64 and ect.

Install

Clone the repository, and add units to your project.

Features

  • ATLibraryLoader(Currently Delphi only): implements a common interface to easily access from delphi to different kinds of profiles(ini, registry, xml, json, and db profiles).
  • ATLogger(Delphi and FPC): A lightweight logging for Delphi/FPC based applications.
  • ATLibraryLoader(Currently Delphi only): makes use dlls becomes simple.
  • ATTimeWatcher(Delphi and FPC): A very lightweight stopwatch.
  • ATOnlyOneAppInst(Currently Delphi only): Ensure only a single instance of the application runs.
  • ATTimer(Delphi and FPC): A high-precision timer in MSWindows.

Useage

Note: These examples are for Windows and the used file paths are hard-coded, so you may make a little changes if the paths not exist or you want to compile to other platforms, there are some complete examples in the samples folder.

ATConfigurator:

pascal
var
  LC: IATConfigurator;
begin
  // Create an ini file.
  LC := NCIni('D:\MyConfig.ini');
pascal
// Set user name.
LC.SetConfig('UserName', 'admin', 'User');
pascal
// The password will be encrypted.
LC.SetConfig('Userpwd', '123456', 'User', True);
pascal
// Set array of key values.   
LC.SetConfig(['IntValue', 'BoolValue', 'FloatValue'], [10, True, 3.14], 'Values');
pascal
// Show Config Text.
ShowMessage(LC.ConfigText);
pascal
// All configs now copied to registry.
LC.CopyTo(NCReg('SoftWare\MyConfig'));
pascal
// All configs now copied to xml.
LC.CopyTo(NCXML('D:\MyConfig.xml'));
pascal
// All configs now copied to json.
LC.CopyTo(NCJSON('D:\MyConfig.json'));
pascal
// All configs now copied to MS Access.
LC.CopyTo(NCDB(...ConnectionStr..., dtMSAccess));
pascal
// Copy all configs to clipbrd.
LC.CopyToClipbrd;
pascal
// Save all configs to stream.
LC.SaveToStream(YourStream);
pascal
// Save all configs to file.
LC.SaveToFile('D:\MyConfig.data');  
...
pascal
end;

ATLogger:

pascal
var
  LLog: IATLogger;
begin
  // Create a file log.
  LLog := NewFileLogger('D:\MyLog\MyLogs.log');
pascal
// You can set a log level. 
LLog.LogLevel := llTrace;
pascal
// Log debug info. 
LLog.D('Output debug info to a file.');
pascal
// Delete all the log files from dir "D:\MyLog\".
//CleanLogFiles(['D:\MyLog\']);
pascal
end;

ATLibraryLoader:

pascal
type
  TMyDll = record
    // exported functions list from dll.
    GetSum: function(A, B: Integer): Integer; stdcall;
    ...
  end;
pascal
var
  LMyDll: TMyDll; 
begin
  // NOTE: ATLibraryLoader can only used in Windows.
pascal
// Load the "MyDll.dll" first.  
DllLoader.Load('MyDll.dll', LMyDll, SizeOf(LMyDll));
pascal
// then call the function.
LMyDll.GetSum(10, 10);
pascal
end;

ATTimeWatcher:

pascal
var
  LTimeWatcher: TATTimeWatcher;
begin
  // The ATTimeWatcher is very very simple to use.
  LTimeWatcher.Start;
  Sleep(500);
  OutputDebugString(PChar(LTimeWatcher.Elapsed));
pascal
// Continue.
Sleep(600);
OutputDebugString(PChar(LTimeWatcher.Elapsed));
pascal
// Restart.
LTimeWatcher.Start;
Sleep(700);
OutputDebugString(PChar(LTimeWatcher.Elapsed));
pascal
end;

ATOnlyOneAppInst:

pascal
In dpr file:
pascal
program EnsureOnlyOneAppInst;
pascal
uses
  Forms,
  ATOnlyOneAppInst,
  ...;
pascal
const
  // You can define your own id.
  CAppGlobalUniqueID = '{F1FB2123-DD15-44DF-B03B-9D724467AA34}_OnlyOneAppInst_Demo';
pascal
procedure MyOnAppCall(ANextPID: UInt64; const ANextParam: string);
begin
  // You can receive the next app's param if it exists.
end;
pascal
begin        
  // NOTE: ATOnlyOneAppInst currently only used in MSWindows.
pascal
Application.Initialize;
pascal
// Check whether the previous app is running.
if OnlyOneAppInst(CAppGlobalUniqueID, MyOnAppCall).IsAppRunning then    
  Exit;
pascal
Application.CreateForm(TFormOOAIMain, FormOOAIMain);
Application.Run;
pascal
end.