unit1.pas

来自「很好地delphi书籍源码」· PAS 代码 · 共 77 行

PAS
77
字号
unit Unit1;

interface

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

type
  TMyObject=class
   private
    Pri_Inf:string;
    { Private declarations }
   public
    Pub_Info:string;
    procedure SetPri_Inf(s:string);
    function  GetPri_Inf:string;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Ext_Info:string;

implementation
function TMyObject.GetPri_Inf: string;
begin
  GetPri_Inf:=Pri_Inf;
end;

procedure TMyObject.SetPri_Inf(s:string);
begin
  Pri_Inf:=s;
end;


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Ext_Info:='向外部变量赋值成功!';
  Caption:=Ext_Info;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with TMyObject.Create do
  begin
    Pub_Info:='向对象内部变量赋值成功!';
    Caption:=Pub_Info;
  end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  with TMyObject.Create do
  begin
    SetPri_Inf('通过接口向对象内部变量赋值成功!');
    Caption:=GetPri_Inf;
  end;

end;

end.

⌨️ 快捷键说明

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