AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Class field lost value!

Ein Thema von WojTec · begonnen am 26. Feb 2010 · letzter Beitrag vom 27. Feb 2010
Antwort Antwort
Seite 1 von 2  1 2      
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Class field lost value!

  Alt 26. Feb 2010, 17:30
Delphi-Quellcode:
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;
So, I create some graphic tool with layers.
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.
  Mit Zitat antworten Zitat
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#2

Re: Class field lost value!

  Alt 26. Feb 2010, 18:14
Please describe what the loop is doing... Or should be doing.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Class field lost value!

  Alt 26. Feb 2010, 18:25
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.
  Mit Zitat antworten Zitat
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#4

Re: Class field lost value!

  Alt 27. Feb 2010, 06:39
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;
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#5

Re: Class field lost value!

  Alt 27. Feb 2010, 10:17
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).
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: Class field lost value!

  Alt 27. Feb 2010, 10:22
Here you're creating a new instance
with TBrightnessLayerEditor.Create(Layer) do
Markus Kinzler
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#7

Re: Class field lost value!

  Alt 27. Feb 2010, 11:15
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?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: Class field lost value!

  Alt 27. Feb 2010, 11:21
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
    Layer.Create(<Params>);
Markus Kinzler
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#9

Re: Class field lost value!

  Alt 27. Feb 2010, 11:31
But

with TBrightnessLayerEditor.Create(Layer) do isn't Layer constructor, TBrightnessLayerEditor is just window.
In this case is also created next Layer instance?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#10

Re: Class field lost value!

  Alt 27. Feb 2010, 12:01
Yes
TBrightnessLayerEditor.Create(Layer) creates a new instance of TBrightnessLayerEditor because TBrightnessLayerEditor is a class and not an object!
Markus Kinzler
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:56 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz