⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pilabel.pas

📁 Delphi高级开发指南是开发程序的好帮手
💻 PAS
字号:
unit PILabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TPackInfoLabel = class(TLabel)
  private
    fPackName, fExeName: string;
    fShowIn: Boolean;
    procedure UpdateInfo;
    procedure ShowInfo;
    procedure SetString (Value: string);
    procedure SetShowIn (Value: Boolean);
  public
    constructor Create (AOwner: TComponent); override;
    procedure Loaded; override;
  published
    property PackName: string
      read fPackName write SetString;
    property ExeName: string
      read fExeName write SetString;
    property ShowInCaption: Boolean
      read fShowIn write SetShowIn;
  end;

procedure Register;

implementation

constructor TPackInfoLabel.Create (AOwner: TComponent);
begin
  inherited;
  if csDesigning in ComponentState then
    UpdateInfo;
end;

procedure TPackInfoLabel.UpdateInfo;
begin
  // get exe name
  SetLength (fExeName, 100);
  GetModuleFileName (MainInstance,
    PChar (fExeName), Length (fExeName));
  fExeName := PChar (fExeName); // length fixup

  // get package name
  SetLength (fPackName, 100);
  if ModuleIsPackage then
  begin
    GetModuleFileName (HInstance,
      PChar (fPackName), Length (fPackName));
    fPackName := PChar (fPackName) // length fixup
  end
  else
    fPackName := 'Not packaged';
  // set label caption
  if fShowIn then
    ShowInfo;
end;

procedure TPackInfoLabel.Loaded;
begin
  UpdateInfo;
end;

procedure TPackInfoLabel.ShowInfo;
begin
  Caption := fExeName + ' ' + fPackName;
end;

procedure TPackInfoLabel.SetShowIn (Value: Boolean);
begin
  if Value <> FShowIn then
  begin
    fShowIn := Value;
    if FShowIn then
      ShowInfo
    else
      Caption := Name;
  end;
end;

procedure TPackInfoLabel.SetString (Value: string);
begin
  // discard the new value
end;

procedure Register;
begin
  RegisterComponents('DDHB', [TPackInfoLabel]);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -