Тема: классы
Показать сообщение отдельно
  #7  
Старый 15.10.2010, 20:12
Аватар для dr. F.I.N.
dr. F.I.N. dr. F.I.N. вне форума
I Like it!
 
Регистрация: 12.12.2009
Адрес: Россия, г. Новосибирск
Сообщения: 663
Версия Delphi: D6/D7
Репутация: 26643
По умолчанию

Ну как вариант:

Код:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    BitBtn1: TBitBtn;
    SpeedButton1: TSpeedButton;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TSuperClass = class
  public
    function MyClassName: String;
    procedure SetMyLeft(NewLeft: Integer);
  end;

{ TSuperClass }

function TSuperClass.MyClassName: String;
begin
  Result := Self.ClassName;
end;

procedure TSuperClass.SetMyLeft(NewLeft: Integer);
begin
  TWinControl(Self).Left := NewLeft;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(TSuperClass(Sender).MyClassName);
  TSuperClass(Sender).SetMyLeft(Random(300));
end;

end.

Код:
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 979
  Height = 563
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object SpeedButton1: TSpeedButton
    Left = 256
    Top = 128
    Width = 73
    Height = 25
    OnClick = Button1Click
  end
  object Button1: TButton
    Left = 256
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object BitBtn1: TBitBtn
    Left = 256
    Top = 96
    Width = 75
    Height = 25
    Caption = 'BitBtn1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object CheckBox1: TCheckBox
    Left = 256
    Top = 160
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 2
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 256
    Top = 184
    Width = 121
    Height = 21
    TabOrder = 3
    Text = 'Edit1'
    OnClick = Button1Click
  end
end
Проверено на Д6. Работает 100%
__________________
Грамотно поставленный вопрос содержит не менее 50% ответа.
Грамотно поставленная речь вызывает уважение, а у некоторых даже зависть.
Ответить с цитированием