AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

My Delphi 2010 is sick

Ein Thema von WojTec · begonnen am 4. Jul 2012 · letzter Beitrag vom 9. Jul 2012
Antwort Antwort
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.045 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#1

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 00:35
The GradientChange event is assigned to edtSteps which is created before the CheckBox (by reading the form from the dfm file). Reading the value and setting it to the spin edit then triggers the event.

There are several ways to fix this:

If you have access to the code of the spinedit:
- define the events after all other properties so they are assigned after the value is set (because of the order they are written to the dfm then)

If you don't have access to the code:
- add a condition to your GradientChange event that prevents it from being triggered during form creation
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#2

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 06:40
Another possibility would be to reverse the creation order of the components.
However, this is not a robust way to generally solve the problem once and for all.

Stevie's ideas are -of course- correct, but I don't like having to add code in each and every event handler for the rest of my (programmers) life just to make sure, I don't get caught in these side effects caused by the loading order of components.

Personally, I would remove the design time links from the component events to the event handlers and add them in the FormActivate, after everything has been loaded. As FormActivate is called each time the form is displayed (i.e. 'activated'), I would also make sure, my initialization code is only called once.

This is a decent and robust design pattern which avoids all those caveats during form initialization:

Delphi-Quellcode:
Procedure TMyForm.MyFormInitialize;
Begin
  MyControl.OnDoSomething := MyFormDoSomethingEventHandler;
// ... more init stuff here
End;

Procedure TMyForm.FormActivate(Sender : TObject);
Begin
  if not FInitialized Then MyFormInitialize;
  FInitialized := True;
End;
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.372 Beiträge
 
Delphi 12 Athens
 
#3

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 08:18
Es muß nichtmal am OnGradientChange liegen, denn dieses wird auch nochmal im OnColorChange aufgerufen.

Delphi-Quellcode:
Procedure TMyForm.MyFormInitialize;
Begin
  MyControl.OnDoSomething := MyFormDoSomethingEventHandler;
// ... more init stuff here
End;

Procedure TMyForm.FormActivate(Sender : TObject);
Begin
  if not FInitialized Then MyFormInitialize;
  FInitialized := True;
End;
Also entweder das Event später dranhängen

oder es ignorieren (innerhalb der Komponente oder im Event)
Delphi-Quellcode:
procedure TGradientDialog.GradientChange(Sender: TObject);
var
  I: Integer;
  A: TColorArray;
begin
  if FUpdate or not Assigned(cbReverse) then Exit;
Delphi-Quellcode:
procedure TGradientDialog.GradientChange(Sender: TObject);
var
  I: Integer;
  A: TColorArray;
begin
  if FUpdate or not Assigned(cbReverse) then Exit;
Es wird ja am Ende sowieso aufgerufen, also kann man es auch einfach überspringen, ohne etwas zu beachten.
TGradientDialog.Create => ColorChange => GradientChange
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#4

Re: My Delphi 2010 is sick

  Alt 9. Jul 2012, 18:34
Thanks guys for ideas. Temporary I changed creation order, but it isn't real solution.
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.045 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#5

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 13:59
Stevie's ideas are -of course- correct, but I don't like having to add code in each and every event handler for the rest of my (programmers) life just to make sure, I don't get caught in these side effects caused by the loading order of components.
That is true for the second solution which would only be a workaround for a bug in the TBMDSpinEdit class. Fixing this was my first solution because reading a component from the dfm should not trigger events on itself. (for example TEdit never triggers the OnChange when reading its Text property from the dfm)
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight

Geändert von Stevie ( 9. Jul 2012 um 14:02 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 20:02 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-2025 by Thomas Breitkreuz