![]() |
Class field lost value!
Delphi-Quellcode:
So, I create some graphic tool with layers.
var
Index: Integer; Layer: TCustomFilterLayer; begin Index := lbLayers.ItemIndex; if Index <> - 1 then begin if lbLayers.Items.Objects[Index] is TCustomFilterLayer then begin Layer := lbLayers.Items.Objects[Index] as TCustomFilterLayer; if Layer is TBrightnessAdjustmentLayer then begin Layer := Layer as TBrightnessAdjustmentLayer; with TBrightnessLayerEditor.Create(Layer) do begin SetAmount(vtInteger, -100, 100, TBrightnessAdjustmentLayer(Layer).Amount); // Here is something wrong :( // Here is ok end; end; end; end; end; There is problem with this procedure: when - TBrightnessAdjustmentLayer(Layer).Amount is always 0 (default from Create()), also if is setup other value... Other parameters from TCustomFilterLayer are ok. Why and how to fix? Layer is display with correct setting. |
Re: Class field lost value!
Please describe what the loop is doing... Or should be doing.
|
Re: Class field lost value!
When I click on list item should be open editor for object stored in this item.
Window is opening, but field in stored object don't have values setted early, but default form their class constructor. In oder word I wanna edit object stored in list items. |
Re: Class field lost value!
So why do you create another TBrighnessAdjustmentLayer then?
This should work (I removed the 'create' and got rid of some begin/end and other unimportant stuff):
Delphi-Quellcode:
var
Index: Integer; Layer: TCustomFilterLayer; begin Index := lbLayers.ItemIndex; if Index <> - 1 then if lbLayers.Items.Objects[Index] is TCustomFilterLayer then begin Layer := lbLayers.Items.Objects[Index] as TCustomFilterLayer; if Layer is TBrightnessAdjustmentLayer then SetAmount(vtInteger, -100, 100, TBrightnessAdjustmentLayer(Layer).Amount); end; end; |
Re: Class field lost value!
Where I create 2nd object? T*Editor is just descendant of TForm (it's more complicated structure, but base class for any editor is TForm) where I have controls to edit layer ;)
I did that I set values in editor contructor. But I still don't understand why this value is zero? Before constructor is ok, in constructor is ok, after constructor is not ok... (only this field is bad, fields from previous classes are ok at all). |
Re: Class field lost value!
Here you're creating a new instance
Delphi-Quellcode:
with TBrightnessLayerEditor.Create(Layer) do
|
Re: Class field lost value!
Why here is created new obj? In this form constructor is reintroduced and assigning parameter to private filed. So, how to change it to do not make new obj and just work on existing one?
|
Re: Class field lost value!
In Delphi a constructor can be called als "normal" class method. But then you have to call it on an instance! You call it on a class, so the constructor creates a new instance.
Try
Delphi-Quellcode:
Layer.Create(<Params>);
|
Re: Class field lost value!
But
Delphi-Quellcode:
isn't Layer constructor, TBrightnessLayerEditor is just window.
with TBrightnessLayerEditor.Create(Layer) do
In this case is also created next Layer instance? |
Re: Class field lost value!
Yes
Delphi-Quellcode:
creates a new instance of TBrightnessLayerEditor because TBrightnessLayerEditor is a class and not an object!
TBrightnessLayerEditor.Create(Layer)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:40 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz