Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
Delphi 10 Seattle Enterprise
|
AW: Change one value + many OnChange events = stack overflow
31. Dez 2011, 13:06
- EnableAutoChange/DisableAutoChange
IMHO it would be better to use a Flag to dis-/enable the execution of the Event-Code
Delphi-Quellcode:
procedure TMainForm.RGBChange(Sender: TObject);
begin
if not EnabledUpdateFlag then
Exit;
UpdateColor(Sender, RGBChange, SetRGBValues(edtR.AsInteger, edtG.AsInteger, edtB.AsInteger));
end;
procedure TMainForm.UpdateColor(Sender: TObject; Event: TNotifyEvent; const AColor: TColor);
var
R, G, B: Byte;
H, S, L: Int32;
C, M, Y, K: Byte;
CIEL, CIEa, CIEb: Double;
begin
EnabledUpdateFlag := False;
try
...
finally
EnableUpdateFlag := True;
end;
end;
or like this
Delphi-Quellcode:
procedure TMainForm.UpdateColor(Sender: TObject; Event: TNotifyEvent; const AColor: TColor);
var
R, G, B: Byte;
H, S, L: Int32;
C, M, Y, K: Byte;
CIEL, CIEa, CIEb: Double;
begin
if not EnabledUpdateFlag then
Exit;
EnabledUpdateFlag := False;
try
...
finally
EnableUpdateFlag := True;
end;
end;
Now u don't have to set/reset all the Event-Properties (and u can't miss one of them)
- Useless Method-Parameters
What are the parameters used for ... seems to me useless
Delphi-Quellcode:
procedure TMainForm.DisableAutoChange(Sender: TObject; Event: TNotifyEvent);
begin // Sender and Event are never used in this Method, so they are useless!
HSLPicker.OnChange := nil;
SLPicker.OnChange := nil;
HuePicker.OnChange := nil;
HSVPicker.OnChange := nil;
LightnessPicker.OnChange := nil;
edtR.OnChange := nil;
edtG.OnChange := nil;
edtB.OnChange := nil;
edtH.OnChange := nil;
edtS.OnChange := nil;
edtL.OnChange := nil;
edtM.OnChange := nil;
edtM.OnChange := nil;
edtY.OnChange := nil;
edtK.OnChange := nil;
edtCIEL.OnChange := nil;
edtCIEa.OnChange := nil;
edtCIEb.OnChange := nil;
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
|
|
Zitat
|