Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Доступ к защищенным свойствам

Delphi , Компоненты и Классы , Свойства и События

Доступ к защищенным свойствам

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

{*** It is not always necessary to write a new class when you miss the properties you need ***}

 { 
  Let's say, you writing a program with some standard controls on it's form. 
  One of the components is a TProgressBar. 
  All components, except the progressbar, are yellow (brrrr!!!) 
  but it is not possible to change the color of the progressbar the normal way. 
  There are three things that you can do: 

  1. Leave it this way 
  2. Write a new component 
  3. Try to use WinAPI 

  OR try this: 
}

 // Put this on top of your unit 
type
  TAccessControl = class(TWinControl)
    public
     property Color;
  end;

 // and put into TForm1.FormCreate() the following code: 

  TAccessControl(MyProgressBar).Color:= clYellow;

 { 
  This is possible because TwinControl is the immediate ancestor. 
  There is also another trick to give a existing class more functionality 
  without the need of creating a new component, for example: 
}

 type
  // Just a few lines of code and your TLabel 
 // components on the form has more 
 // functionality without writing a new class 
 TLabel = class(stdctrls.TLabel)
  public
    procedure SayHello();
  end;

  // ... 
procedure TLabel.SayHello();
 begin
   ShowMessage( 'I just want to say hello (and not hello world!)');
 end;


 // As you know the Custom version of a class does not 
// publish all it's properties, so you can do it the same way as with TLabel. 

type
  TTheBaseClass = class(UnitName.TTheBaseClass)
  public
    property Align;
    property Color;
    property YourProp;
    {etc etc}
  end;

 { 
  NOTES: 
  - You can never add new published properties when controls properties are stored 
    in the DFM file (on a form) 
  - You can put modified classes into another unit file so that you can add it 
    AS THE LAST UNIT to the uses clause. 

  I hope you find it usable. 
}

Статья Доступ к защищенным свойствам раздела Компоненты и Классы Свойства и События может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Свойства и События ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100
19.04.2024 02:23:32/0.032901048660278/0