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

📄 titlef.pas

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

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    RadioButton2: TRadioButton;
    RadioButton1: TRadioButton;
    procedure AnyClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  TypInfo;

{$R *.DFM}

procedure TForm1.AnyClick(Sender: TObject);
var
  PropInfo: PPropInfo;
  Capt: string;
//  pcCapt: array [0..100] of Char;
begin
  // we'd like to write:
  // Sender.Caption := Sender.Caption + '*';

{  // Solution 1:

  // get the current value
  (Sender as TControl).GetTextBuf (
    pcCapt, sizeof (pcCapt));
  // add a *
  StrCat (pcCapt, '*');
  // set the new value
  (Sender as TControl).SetTextBuf (pcCapt);}

  // Solution 2:

  // get property RTTI
  PropInfo := GetPropInfo (Sender.ClassInfo, 'Caption');
  // try again
  if PropInfo = nil then
    PropInfo := GetPropInfo (Sender.ClassInfo, 'Text');

  // if found, apply the new value
  if PropInfo <> nil then
  begin
    Capt := GetStrProp (Sender, PropInfo);
    Capt := Capt + '*';
    SetStrProp (Sender, PropInfo, Capt);
  end;
end;

end.

⌨️ 快捷键说明

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