Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.07.20;
Скачать: CL | DM;

Вниз

Как узнать, кто является Sender ом?   Найти похожие ветки 

 
Alex_C   (2008-06-20 10:38) [0]

Допустим: при вызове PupUp меню, нужно изменить цвет или font компонента, который его вызвал.
Пробовал так:
(Sender as TControl).Font := FontDialog1.Font - возникает ошибка при компиляции "Undeclared identifier: font", хотя у TContro по хелпу св-во font есть.


 
clickmaker ©   (2008-06-20 10:40) [1]

PopupComponent?


 
Ega23 ©   (2008-06-20 10:43) [2]


> хотя у TContro по хелпу св-во font есть.


Только оно у TControl - protected property


 
TUserClass   (2008-06-20 10:52) [3]

Можно так ... тока не знаю хорошо ли :

type
 TForm1 = class(TForm)
   Label1: TLabel;
   Button1: TButton;
   procedure Label1Click(Sender: TObject);
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
   procedure ChangeFont (Sender : TObject);
 end;

var
 Form1: TForm1;

implementation
procedure TForm1.ChangeFont (Sender : TObject);
begin
 If Sender.ClassName = "TLabel" then begin
   (Sender as TLabel).Font.Style := (Sender as TLabel).Font.Style + [fsBold];
 end else If Sender.ClassName = "TButton" then begin
   (Sender as TButton).Font.Style := (Sender as TButton).Font.Style + [fsBold];
 end else If Sender.ClassName = ...
end;
{$R *.dfm}

procedure TForm1.Label1Click(Sender: TObject);
begin
 ChangeFont (Sender);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 ChangeFont (Sender);
end;


 
Ega23 ©   (2008-06-20 10:58) [4]


> тока не знаю хорошо ли :


Не хорошо.


 
TUserClass   (2008-06-20 11:01) [5]

Удалено модератором


 
Alex_C   (2008-06-20 11:02) [6]

Всем спасибо! Все понял!
Самое простое так:

(PopupMenu.PopupComponent as TLabel).Font.Assign(FontDialog.Font);


 
Ega23 ©   (2008-06-20 11:04) [7]


> (PopupMenu.PopupComponent as TLabel).Font.Assign(FontDialog.
> Font);


if (PopupMenu.PopupComponent is TLabel) then
TLabel(PopupMenu.PopupComponent).Font.Assign(...)


 
Игорь Шевченко ©   (2008-06-20 11:06) [8]


> Самое простое так:


> (PopupMenu.PopupComponent as TLabel).Font.Assign(FontDialog.
> Font);


Самое некривое через GetObjectProp и Assign



Страницы: 1 вся ветка

Текущий архив: 2008.07.20;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.015 c
2-1213942409
TUserClass
2008-06-20 10:13
2008.07.20
Путь к своей DLL ...


3-1202505930
DiX
2008-02-09 00:25
2008.07.20
Сортировка таблицы


1-1195553133
DVM
2007-11-20 13:05
2008.07.20
TWinControl.WMPaint от Delphi7 запостите пожалуйста.


1-1195741012
AndrewK
2007-11-22 17:16
2008.07.20
Проблема с хинтом в DLL


2-1213887146
Res
2008-06-19 18:52
2008.07.20
файл и потоки