(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
unit inttlbl;

interface

uses
  Classes, SysUtils, Dialogs, Contnrs, StdCtrls;

type
  LangLoader = function(lbl, lang: string): string;
  TLabel = class(StdCtrls.TLabel)
  private
    first: boolean;
    origcap: string;
    xcld: boolean;
    function GetExclude(): boolean;
    procedure SetExclude(newsts: boolean);
  public
    constructor Create(own: TComponent); override;
    procedure LangLoad(p: LangLoader; lang: string);
    property Exclude: boolean read GetExclude write SetExclude;
  end;
  procedure LangLoadAllTLabel(p: LangLoader; lang: string);

implementation

var
  all: TObjectList = nil;

procedure LangLoadAllTLabel(p: LangLoader; lang: string);

var
  lblp: Pointer;
  lbl: TLabel;

begin
  for lblp in all do begin
    lbl := TLabel(lblp);
    if not lbl.Exclude then begin
      lbl.LangLoad(p, lang);
    end;
  end;
end;

constructor TLabel.Create(own: TComponent);

begin
  inherited Create(own);
  if all = nil then begin
     all := TObjectList.Create(true);
  end;
  all.Add(self);
  first := true;
  xcld := false;
end;

procedure TLabel.LangLoad(p: LangLoader; lang: string);

begin
  if first then begin
     origcap := Caption;
     first := false;
  end;
  Caption := p(origcap, lang);
end;

function TLabel.GetExclude(): boolean;

begin
  GetExclude := xcld;
end;

procedure TLabel.SetExclude(newsts: boolean);

begin
  xcld := newsts;
end;

end.
