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

Вниз

Проблема с свойствами объекта   Найти похожие ветки 

 
Квэнди ©   (2006-06-22 11:15) [0]

Не могу понять в чем праблема.
В desing-time устанавливаю значения свойств а run-time они не загружаются.

Свойство:
//Класс для свойства "Start Button"
type
TMSLMDIPanelPropertyStartButton = class(TPersistent)
private
//Поля свойств
FWidth: integer;
FHeight: integer;
FHorizontalSpace: integer;
FVerticalSpace: integer;
FVisible: boolean;
FGlyph: TBitmap;
FHint: string;
FCaption: TCaption;
FEnabled: boolean;
FDropDownMenu: TPopupMenu;
FFont: TFont;

//Поля событий
FOnChange: TNotifyEvent;

protected
//Методы обработки свойств
procedure SetWidth(Value: integer);
procedure SetHeight(Value: integer);
procedure SetHorizontalSpace(Value: integer);
procedure SetVerticalSpace(Value: integer);
procedure SetVisible(Value: boolean);
procedure SetGlyph(Value: TBitmap);
procedure SetHint(Value: string);
procedure SetCaption(Value: TCaption);
procedure SetEnabled(Value: boolean);
procedure SetDropDownMenu(Value: TPopupMenu);
procedure SetFont(Value: TFont);

//Методы событий
procedure DoFontChangeLink(Sender: TObject);

public
//Систамные методы
constructor Create;
destructor Destroy; override;
procedure Notification(AComponent: TComponent; Operation: TOperation);

published
//Свойства
property Width: integer read FWidth write SetWidth default 50;
property Height: integer read FHeight write SetHeight default 25;
property HorizontalSpace: integer read FHorizontalSpace write SetHorizontalSpace default 5;
property VerticalSpace: integer read FVerticalSpace write SetVerticalSpace default 3;
property Visible: boolean read FVisible write SetVisible default false;
property Glyph: TBitmap read FGlyph write SetGlyph;
property Hint: string read FHint write SetHint;
property Caption: TCaption read FCaption write SetCaption;
property Enabled: boolean read FEnabled write SetEnabled default true;
property DropDownMenu: TPopupMenu read FDropDownMenu write SetDropDownMenu;
property Font: TFont read FFont write SetFont;

//События
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;

implementation

//Системные методы++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Конструктор класса
constructor TMSLMDIPanelPropertyStartButton.Create;
begin
inherited Create;

FFont:=TFont.Create;
FFont.OnChange:=DoFontChangeLink;
FGlyph:=TBitmap.Create;
FDropDownMenu:=TPopupMenu.Create(nil);

FWidth:=133;
FHeight:=25;
FHorizontalSpace:=5;
FVerticalSpace:=3;
FVisible:=true;
end;

//Деструктор класса
destructor TMSLMDIPanelPropertyStartButton.Destroy;
begin
FFont.Free;
FGlyph.Free;
FDropDownMenu.Free;

inherited;
end;

//Уведомление класса
procedure TMSLMDIPanelPropertyStartButton.Notification(AComponent: TComponent; Operation: TOperation);
begin
if (AComponent = DropDownMenu) and (Operation = opRemove) then DropDownMenu := nil;
end;
//Системные методы--------------------------------------------------------------

//Методы обработки свойств++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Метод записи свойства "Width"
procedure TMSLMDIPanelPropertyStartButton.SetWidth(Value: integer);
begin
if Value<>FWidth then FWidth:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Height"
procedure TMSLMDIPanelPropertyStartButton.SetHeight(Value: integer);
begin
if Value<>FHeight then FHeight:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "HorizontalSpace"
procedure TMSLMDIPanelPropertyStartButton.SetHorizontalSpace(Value: integer);
begin
if Value<>FHorizontalSpace then FHorizontalSpace:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "VerticalSpace"
procedure TMSLMDIPanelPropertyStartButton.SetVerticalSpace(Value: integer);
begin
if Value<>FVerticalSpace then FVerticalSpace:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Visible"
procedure TMSLMDIPanelPropertyStartButton.SetVisible(Value: boolean);
begin
if Value<>FVisible then FVisible:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Glyph"
procedure TMSLMDIPanelPropertyStartButton.SetGlyph(Value: TBitmap);
begin
FGlyph.Assign(Value);
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Hint"
procedure TMSLMDIPanelPropertyStartButton.SetHint(Value: string);
begin
if Value<>FHint then FHint:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Caption"
procedure TMSLMDIPanelPropertyStartButton.SetCaption(Value: TCaption);
begin
if Value<>FCaption then FCaption:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Enabled"
procedure TMSLMDIPanelPropertyStartButton.SetEnabled(Value: boolean);
begin
FEnabled:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "DropDownMenu"
procedure TMSLMDIPanelPropertyStartButton.SetDropDownMenu(Value: TPopupMenu);
begin
FDropDownMenu:=Value;
if Assigned(FOnChange) then OnChange(Self);
end;

//Метод записи свойства "Font"
procedure TMSLMDIPanelPropertyStartButton.SetFont(Value: TFont);
begin
FFont.Assign(Value);
if Assigned(FOnChange) then OnChange(Self);
end;
//Методы обработки свойств------------------------------------------------------

//Внешние методы++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Метод обработки изменения свойства "Font"
procedure TMSLMDIPanelPropertyStartButton.DoFontChangeLink(Sender: TObject);
begin
if Assigned(FOnChange) then OnChange(Self);
end;
//Внешние методы----------------------------------------------------------------

Код обработки свойства в классе котором оно должно стоять

В privat класса описано поле
FStartButton: TMSLMDIPanelPropertyStartButton;

В protected класса описана процедура
procedure SetStartButton(Value: TMSLMDIPanelPropertyStartButton);
procedure DoStartButton(Sender: TObject);

В published класса описано свойство
property SartButton: TMSLMDIPanelPropertyStartButton read FStartButton write SetStartButton;

В конструкторе класса
FStartButton:=TMSLMDIPanelPropertyStartButton.Create;
FStartButton.OnChange:=DoStartButton;

Реализация:

//Метод записи свойства "StartButton"
procedure TMSLMDIPanel.SetStartButton(Value: TMSLMDIPanelPropertyStartButton);
begin
FStartButton.Assign(Value);
end;

//Метод события "StartButton"
procedure TMSLMDIPanel.DoStartButton(Sender: TObject);
begin
with GlavnButton do begin
Width:=FStartButton.Width;
Height:=FStartButton.Height;
Visible:=FStartButton.Visible;
Glyph.Assign(FStartButton.Glyph);
Hint:=FStartButton.Hint;
Caption:=FStartButton.Caption;
Enabled:=FStartButton.Enabled;
Font.Assign(FStartButton.Font);
end;
Invalidate;
end;


Если по умолчанию указать, то при следующей загрузке проекта там становятся "Нули", а если не по умолчанию то при следующей загрузке проекта значения восстанавливаются (и все это происходит в design-time).
А с run-time(ом) получается, что конструктор не влияет на значания полей.

Так что самое интересное с run-time(ом), что сбрасываются только простые типы данных!


 
Desdechado ©   (2006-06-22 12:14) [1]

тебе сюда
http://www.delphimaster.ru/cgi-bin/forum.pl?n=12


 
Квэнди ©   (2006-06-22 12:26) [2]

Извиняюсь, да простят меня модераторы за дублирование тем (


 
Amoeba ©   (2006-06-22 12:45) [3]

А в отладчике что наблюдается?


 
Квэнди ©   (2006-06-23 09:58) [4]

1 Ошибок нет
2 В design-time при повторной загрузке проекта значания типа integer получают 0
3 Соответственно и в run-time такая же история


 
Сергей М. ©   (2006-06-23 10:01) [5]


> Квэнди ©   (23.06.06 09:58) [4]


Для начала унаследуй свой класс от TComponent



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

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

Наверх




Память: 0.49 MB
Время: 0.049 c
2-1150833840
Glivera
2006-06-21 00:04
2006.07.09
Сохранение Excel документа


2-1151161757
Марина
2006-06-24 19:09
2006.07.09
Как поместить фоном списка картинку как в FlashGet ?


15-1150107969
Иксик
2006-06-12 14:26
2006.07.09
День России


2-1150865087
mctarik
2006-06-21 08:44
2006.07.09
Как передать строку в коммандную строку...


1-1148563500
yahaha
2006-05-25 17:25
2006.07.09
Курсор в WebBrowser