2020-04-04 21:44:15 +00:00
|
|
|
unit Utils;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-09-23 11:19:08 +00:00
|
|
|
Classes, SysUtils, Graphics, Controls, StdCtrls, ComCtrls, Dialogs, Forms,
|
2020-08-22 17:31:05 +00:00
|
|
|
Globals;
|
2020-04-04 21:44:15 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
type
|
|
|
|
TToolbarPosition = (tpTop, tpLeft, tpRight);
|
|
|
|
|
2020-09-23 11:19:08 +00:00
|
|
|
procedure InitForm(AForm: TForm);
|
|
|
|
|
2020-09-20 20:22:00 +00:00
|
|
|
procedure AddButtonToToolbar(AToolButton: TToolButton; AToolBar: TToolBar);
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition);
|
2020-09-20 20:22:00 +00:00
|
|
|
|
2020-04-04 21:44:15 +00:00
|
|
|
function AnySelected(AListbox: TListBox): Boolean;
|
|
|
|
|
2020-05-10 23:10:20 +00:00
|
|
|
procedure ErrorMsg(const AMsg: String);
|
2020-05-11 16:21:39 +00:00
|
|
|
procedure ErrorMsg(const AMsg: String; const AParams: array of const);
|
2020-05-10 23:10:20 +00:00
|
|
|
|
2020-09-30 21:52:40 +00:00
|
|
|
function CenterString(S: String; Width: Integer): String;
|
2020-09-06 23:24:17 +00:00
|
|
|
function IndexOfString(L: StrDyneVec; s: String): Integer;
|
|
|
|
|
|
|
|
|
2020-04-04 21:44:15 +00:00
|
|
|
implementation
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
uses
|
2020-09-30 21:52:40 +00:00
|
|
|
StrUtils, Math, ToolWin;
|
2020-09-21 21:39:40 +00:00
|
|
|
|
2020-09-20 20:22:00 +00:00
|
|
|
// https://stackoverflow.com/questions/4093595/create-ttoolbutton-runtime
|
|
|
|
procedure AddButtonToToolbar(AToolButton: TToolButton; AToolBar: TToolBar);
|
|
|
|
var
|
|
|
|
lastBtnIdx: integer;
|
|
|
|
begin
|
|
|
|
lastBtnIdx := AToolBar.ButtonCount - 1;
|
|
|
|
if lastBtnIdx > -1 then
|
|
|
|
AToolButton.Left := AToolBar.Buttons[lastBtnIdx].Left + AToolBar.Buttons[lastBtnIdx].Width
|
|
|
|
else
|
|
|
|
AToolButton.Left := 0;
|
|
|
|
AToolButton.Parent := AToolBar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-09-23 11:19:08 +00:00
|
|
|
procedure InitForm(AForm: TForm);
|
|
|
|
begin
|
|
|
|
AForm.Width := AForm.Scale96ToFont(DEFAULT_WIDTH);
|
|
|
|
AForm.Height := AForm.Scale96ToFont(DEFAULT_HEIGHT);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure InitToolbar(AToolbar: TToolbar; APosition: TToolbarPosition);
|
|
|
|
begin
|
|
|
|
// AToolbar.Transparent := false;
|
|
|
|
// AToolbar.Color := clForm;
|
|
|
|
case APosition of
|
|
|
|
tpTop:
|
|
|
|
begin
|
|
|
|
AToolbar.Align := alTop;
|
|
|
|
AToolbar.EdgeBorders := [ebBottom];
|
|
|
|
end;
|
|
|
|
tpLeft:
|
|
|
|
begin
|
|
|
|
AToolbar.Align := alLeft;
|
|
|
|
AToolbar.EdgeBorders := [ebRight];
|
|
|
|
end;
|
|
|
|
tpRight:
|
|
|
|
begin
|
|
|
|
AToolbar.Align := alRight;
|
|
|
|
AToolbar.EdgeBorders := [ebLeft];
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-04 21:44:15 +00:00
|
|
|
function AnySelected(AListBox: TListBox): Boolean;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
for i := 0 to AListbox.Items.Count-1 do
|
|
|
|
if AListbox.Selected[i] then
|
|
|
|
begin
|
|
|
|
Result := true;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-05-10 23:10:20 +00:00
|
|
|
procedure ErrorMsg(const AMsg: String);
|
|
|
|
begin
|
|
|
|
MessageDlg(AMsg, mtError, [mbOK], 0);
|
|
|
|
end;
|
|
|
|
|
2020-05-11 16:21:39 +00:00
|
|
|
procedure ErrorMsg(const AMsg: String; const AParams: array of const);
|
|
|
|
begin
|
|
|
|
ErrorMsg(Format(AMsg, AParams));
|
|
|
|
end;
|
|
|
|
|
2020-09-30 21:52:40 +00:00
|
|
|
|
|
|
|
function CenterString(S: String; Width: Integer): String;
|
|
|
|
var
|
|
|
|
n1, n2: Integer;
|
|
|
|
begin
|
|
|
|
n1 := Width - Length(S);
|
|
|
|
if n1 <= 0 then
|
|
|
|
begin
|
|
|
|
Result := S;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
n1 := n1 div 2;
|
|
|
|
if Length(S) + 2*n1 < Width then
|
|
|
|
n2 := n1+1
|
|
|
|
else
|
|
|
|
n2 := n1;
|
|
|
|
|
|
|
|
Result := DupeString(' ', n1) + S + DupeString(' ', n2);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-09-06 23:24:17 +00:00
|
|
|
function IndexOfString(L: StrDyneVec; s: String): Integer;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
for i := 0 to High(L) do
|
|
|
|
if L[i] = s then
|
|
|
|
begin
|
|
|
|
Result := i;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-04-04 21:44:15 +00:00
|
|
|
end.
|
|
|
|
|