![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как задать порядок присвоения св-в компоненты при создании? [D7, WinXP]
Doma © (2006-10-07 04:48:00)Создал я свой компонет: (код неполный)
usesclasses;
type
TMyComponent = class(TComponent)
private
FFiles: TStrings;
FActive: boolean;
//...
procedureSetActive ( constValue: boolean);
procedureSetFiles ( constValue: TStrings);
public
constructorCreate(AOwner: TComponent);
destructorDestroy; override;
procedureReadFiles(FileName: string);
published
propertyActive: boolean readFActive writeSetActive;
propertyFiles: TStrings readFFiles writeSetFiles;
end;
implementation
{ TMyComponent }
constructorTMyComponent.Create(AOwner: TComponent);
begin
inherited;
FFiles := TStringList.Create;
end;
destructorTMyComponent.Destroy;
begin
FFiles.Free;
FActive := false;
inherited;
end;
procedureTMyComponent.ReadFiles(FileName: string);
begin
//...
end;
procedureTMyComponent.SetActive( constValue: boolean);
vari: integer;
begin
FActive := Value;
if Active then
for i := 0 to FFiles.Count - 1 do // FFiles.Count = 0!!
ReadFiles(FFiles.Strings[i]);
end;
procedureTMyComponent.SetFiles( constValue: TStrings);
begin
FFiles.Assign(Value);
end;
Проблема заключается в том, что если в Design-Time установить св-во компоненты Active = true, и внести в список Files некоторые значения, при запуске сработает метод SetActive, в котором Files будет еще пустой. Как сделать так, чтобы св-ву Active значение присваивалось в последнюю очередь, чтобы всем остальным св-вам значения были уже присвоены?
RASkov (2006-10-07 22:07:00) [1]
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited;
FFiles := TStringList.Create;
FActive := False;
end;
destructor TMyComponent.Destroy;
begin
Active := false;
FFiles.Free;
inherited;
end;
procedure Zagruzit;
var i: Integer;
begin
for i := 0 to FFiles.Count - 1 do
ReadFiles(FFiles.Strings[i]);
end;
procedure Vigruzit;
var i: Integer;
begin
for i := 0 to FFiles.Count - 1 do
UnLoadFiles(FFiles.Strings[i]);
end;
procedure TMyComponent.SetActive(const Value: boolean);
var i: integer;
begin
if FActive<>Value then begin
FActive := Value;
if not(csLoading in ComponentState) and FActive then
Zagruzit else Vigruzit;
end;
end;
procedure TudPluginsManager.Loaded;
begin
inherited;
if Active then Zagruzit;
end;
ИМХО правильно.
Джо (2006-10-07 19:27:00) [2]> [6] Doma © (07.10.06 12:35)
> Спасибо всем за помощь!
> Правда возникла еще одна проблемка - как сделать так, чтобы
> когда закрываешь приложение, срабатывало бы Active := false,
> чтобы выгрузить эти файлы (т.к. эти файлы на самом деле
> dllки и их надо выгружать)
Написать соответствующий код в деструкторе. Деструктор должен быть объявлен как override и в нем должен вызываться inherited (как правило, в самом конце метода).
Doma (2006-10-07 12:35:00) [3]
> jack128 © (07.10.06 12:12) [5]
> нужно переустановить компонент в IDE, тогда поможет..
Да я его перекомпелировал? или этого не достаточно?
В итоге сделал как посоветовал Ketmar © и получилось следующее:
procedureTMyComponent.SetActive( constValue: boolean);
vari: integer;
begin
FActive := Value;
if not(csLoading in ComponentState) then
if Active then
for i := 0 to FFiles.Count - 1 do
ReadFiles(FFiles.Strings[i]);
end;
procedureTudPluginsManager.Loaded;
begin
inherited;
Active := FActive;
end;
Спасибо всем за помощь!
Правда возникла еще одна проблемка - как сделать так, чтобы когда закрываешь приложение, срабатывало бы Active := false, чтобы выгрузить эти файлы (т.к. эти файлы на самом деле dllки и их надо выгружать)
jack128 (2006-10-07 12:12:00) [4]Doma © (07.10.06 12:09) [4]
Не помогает!
нужно переустановить компонент в IDE, тогда поможет..
Doma (2006-10-07 12:09:00) [5]Спасибо за то что уделили мне свое драгоценное время, но
> Percent (07.10.06 09:08) [3]
>
> published
> property Files: TStrings read FFiles write SetFiles;
> property Active: boolean read FActive write SetActive;
> end;
Не помогает!
> Loginov Dmitry © (07.10.06 08:53) [2]
>
> В SetFiles можно добавить строку:
> Active := FActive
А если у меня не только Files надо заполнять, а еще кучу всего?
Сейчас попробую первый вараиан!
Percent (2006-10-07 09:08:00) [6]published
property Files: TStrings read FFiles write SetFiles;
property Active: boolean read FActive write SetActive;
end;
Loginov Dmitry (2006-10-07 08:53:00) [7]В SetFiles можно добавить строку:
Active := FActive
Ketmar (2006-10-07 05:24:00) [8]сохранить Active во временной переменной и по-настоящему установить в перекрытом методе Loaded()?