AGB  ·  Datenschutz  ·  Impressum  







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

My Delphi 2010 is sick

Ein Thema von WojTec · begonnen am 4. Jul 2012 · letzter Beitrag vom 9. Jul 2012
Antwort Antwort
Seite 2 von 3     12 3      
WojTec

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

Re: My Delphi 2010 is sick

  Alt 5. Jul 2012, 10:35
Ok. So, what to do now?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

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

AW: My Delphi 2010 is sick

  Alt 5. Jul 2012, 10:38
cbPath references not an existing Object. It seems that it is never set at all ( 0 = nil = nirvana)
Check if/where you set that variable.
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

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

AW: My Delphi 2010 is sick

  Alt 5. Jul 2012, 12:56
Your dfm file does not match the pas file.

When loading the form it streams the dfm file and creates the components and places the references in the published fields if they exist (yes, you can have a component on your form but no field in your pas file, if you don't need to access it). But it does not work the other way around. If you placed your component field in the published part (which is by default if you dont specify the visibility) but never created it yourself.

Usually the IDE also complains about this when saving your form (like "Field Form1.CheckBox1 does not have a corresponding component. Remove the declaration?")

Also: did you call inherited in your custom constructor?
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
WojTec

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

Re: My Delphi 2010 is sick

  Alt 5. Jul 2012, 13:39
Delphi-Quellcode:
constructor Create(const AFirst, ASecond: TColor; const ASteps: TByteVal);
begin
  inherited Create(Application);

  // ...
end;

// ...

RenderGradient({...}, cbPath.Checked); // <-- no problem

// ...

if cbPath.Checked then // <-- AV here
Component is added to DFM.

Please note 2nd error showing another component (which is working before I add check box), not this check box (1st error). All component are created properly (form --> check box --> build --> run --> ok), due I want to access it in if statement (in function call I used the same propery and no errors).
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

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

AW: My Delphi 2010 is sick

  Alt 5. Jul 2012, 13:45
Enable debug dcus and check where that problem comes from/if components get created properly and assigned to the correct fields.

Also strip down the project to isolate the problem.

Check warnings/hints as they may point to the possible cause.
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

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

AW: My Delphi 2010 is sick

  Alt 5. Jul 2012, 14:23
Can you upload the PAS and DFM?
$2B or not $2B
  Mit Zitat antworten Zitat
WojTec

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

Re: My Delphi 2010 is sick

  Alt 8. Jul 2012, 17:14
Delphi-Quellcode:
object GradientDialog: TGradientDialog
  Left = 0
  Top = 0
  BorderStyle = bsDialog
  Caption = 'Gradient steps'
  ClientHeight = 335
  ClientWidth = 433
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poMainFormCenter
  PixelsPerInch = 96
  TextHeight = 13
  object lblFirstR: TLabel
    Left = 8
    Top = 46
    Width = 11
    Height = 13
    Caption = 'R:'
  end
  object lblFirstG: TLabel
    Left = 8
    Top = 79
    Width = 11
    Height = 13
    Caption = 'G:'
  end
  object lblFirstB: TLabel
    Left = 8
    Top = 112
    Width = 10
    Height = 13
    Caption = 'B:'
  end
  object lblSecondR: TLabel
    Left = 8
    Top = 164
    Width = 11
    Height = 13
    Caption = 'R:'
  end
  object lblSecondG: TLabel
    Left = 8
    Top = 197
    Width = 11
    Height = 13
    Caption = 'G:'
  end
  object lblSecondB: TLabel
    Left = 9
    Top = 230
    Width = 10
    Height = 13
    Caption = 'B:'
  end
  object Bevel: TBevel
    Left = 8
    Top = 295
    Width = 417
    Height = 3
    Shape = bsTopLine
  end
  object FirstSwatch: TmbColorPreview
    Left = 76
    Top = 45
    Width = 29
    Height = 93
    BlockSize = 4
    SwatchStyle = True
    OnColorChange = ColorChange
  end
  object edtRFirst: TBMDSpinEdit
    Left = 25
    Top = 45
    Width = 45
    Height = 27
    TabOrder = 0
    OnChange = FirstChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 2366701
    Precision = 0
    TrackBarEnabled = False
  end
  object edtGFirst: TBMDSpinEdit
    Left = 25
    Top = 78
    Width = 45
    Height = 27
    TabOrder = 1
    OnChange = FirstChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 5285376
    Precision = 0
    TrackBarEnabled = False
  end
  object edtBFirst: TBMDSpinEdit
    Left = 25
    Top = 111
    Width = 45
    Height = 27
    TabOrder = 2
    OnChange = FirstChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 9580590
    Precision = 0
    TrackBarEnabled = False
  end
  object SecondSwatch: TmbColorPreview
    Left = 76
    Top = 163
    Width = 29
    Height = 93
    BlockSize = 4
    SwatchStyle = True
    OnColorChange = ColorChange
  end
  object edtRSecond: TBMDSpinEdit
    Left = 24
    Top = 163
    Width = 45
    Height = 27
    TabOrder = 3
    OnChange = SecondChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 2366701
    Precision = 0
    TrackBarEnabled = False
  end
  object edtGSecond: TBMDSpinEdit
    Left = 25
    Top = 196
    Width = 45
    Height = 27
    TabOrder = 4
    OnChange = SecondChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 5285376
    Precision = 0
    TrackBarEnabled = False
  end
  object edtBSecond: TBMDSpinEdit
    Left = 25
    Top = 229
    Width = 45
    Height = 27
    TabOrder = 5
    OnChange = SecondChange
    Increment = 1.000000000000000000
    MaxValue = 255.000000000000000000
    Value = 255.000000000000000000
    AsInteger = 255
    GuageBeginColor = clWhite
    GuageEndColor = 9580590
    Precision = 0
    TrackBarEnabled = False
  end
  object btnOk: TButton
    Left = 269
    Top = 304
    Width = 75
    Height = 23
    Caption = 'OK'
    Default = True
    ModalResult = 1
    TabOrder = 7
  end
  object btnCancel: TButton
    Left = 350
    Top = 304
    Width = 75
    Height = 23
    Cancel = True
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 8
  end
  object edtSteps: TSpTBXSpinEdit
    Left = 60
    Top = 268
    Width = 45
    Height = 21
    Alignment = taLeftJustify
    NumbersOnly = True
    TabOrder = 6
    OnChange = GradientChange
    SkinType = sknWindows
    ExtendedAccept = True
    SpinButton.Left = 27
    SpinButton.Top = 0
    SpinButton.Width = 14
    SpinButton.Height = 17
    SpinButton.Align = alRight
    SpinButton.DrawPushedCaption = False
    SpinButton.SkinType = sknWindows
    SpinOptions.MaxValue = 256.000000000000000000
    SpinOptions.MinValue = 1.000000000000000000
    SpinOptions.Value = 1.000000000000000000
  end
  object pnlGradientMapHolder: TPanel
    Left = 8
    Top = 8
    Width = 417
    Height = 12
    BevelOuter = bvLowered
    ShowCaption = False
    TabOrder = 11
    object imgGradient: TImage32
      Left = 1
      Top = 1
      Width = 415
      Height = 10
      Align = alClient
      Bitmap.ResamplerClassName = 'TNearestResampler'
      BitmapAlign = baTopLeft
      ParentShowHint = False
      Scale = 1.000000000000000000
      ScaleMode = smNormal
      ShowHint = True
      TabOrder = 0
    end
  end
  object cbReverse: TCheckBox
    Left = 8
    Top = 307
    Width = 97
    Height = 17
    Caption = 'Reverse'
    TabOrder = 12
    OnClick = ColorChange
  end
  object Gradient: TmbColorPalette
    Left = 119
    Top = 42
    Width = 306
    Height = 17
    HintFormat = 'RGB(%r, %g, %b)'#13'Hex: %hex'
    AutoHeight = True
    CellSize = 17
    CellStyle = csCorel
    TabOrder = 13
    ShowHint = True
    ParentShowHint = False
  end
end
Delphi-Quellcode:
unit GradientStepsDlg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;

type
  TGradientDialog = class(TForm)
    lblFirstR: TLabel;
    lblFirstG: TLabel;
    lblFirstB: TLabel;
    lblSecondR: TLabel;
    lblSecondG: TLabel;
    lblSecondB: TLabel;
    Bevel: TBevel;
    FirstSwatch: TmbColorPreview;
    edtRFirst: TBMDSpinEdit;
    edtGFirst: TBMDSpinEdit;
    edtBFirst: TBMDSpinEdit;
    SecondSwatch: TmbColorPreview;
    edtRSecond: TBMDSpinEdit;
    edtGSecond: TBMDSpinEdit;
    edtBSecond: TBMDSpinEdit;
    btnOk: TButton;
    btnCancel: TButton;
    edtSteps: TSpTBXSpinEdit;
    pnlGradientMapHolder: TPanel;
    imgGradient: TImage32;
    cbReverse: TCheckBox;
    Gradient: TmbColorPalette;
    procedure FirstChange(Sender: TObject);
    procedure SecondChange(Sender: TObject);
    procedure GradientChange(Sender: TObject);
    procedure ColorChange(Sender: TObject);
  private
    FUpdate: Boolean;
    procedure RenderGradient;
  public
    constructor Create(const AFirst, ASecond: TColor; const ASteps: TByteVal); reintroduce;
  end;

var
  GradientDialog: TGradientDialog;

implementation

{$R *.dfm}

procedure TGradientDialog.RenderGradient;
begin
  imgGradient.Bitmap.SetSizeFrom(imgGradient);
  imgGradient.Bitmap.Clear;
  TGradient.Linear(imgGradient.Bitmap, Point(0, imgGradient.Bitmap.Height div 2),
    Point(imgGradient.Bitmap.Width, imgGradient.Bitmap.Height div 2),
    ColorArray([FirstSwatch.Color, SecondSwatch.Color]), cbReverse.Checked
  );
end;

constructor TGradientDialog.Create(const AFirst, ASecond: TColor;
  const ASteps: TByteVal);
var
  R, G, B: Byte;
begin
  inherited Create(Application);

  FUpdate := True;
  try
    FirstSwatch.Color := AFirst;
    GetRGBValues(AFirst, R, G, B);
    edtRFirst.AsInteger := R;
    edtGFirst.AsInteger := G;
    edtBFirst.AsInteger := B;

    SecondSwatch.Color := ASecond;
    GetRGBValues(ASecond, R, G, B);
    edtRSecond.AsInteger := R;
    edtGSecond.AsInteger := G;
    edtBSecond.AsInteger := B;
  finally
    FUpdate := False;
    edtSteps.Value := ASteps;
    ColorChange(nil);
  end;
end;

procedure TGradientDialog.FirstChange(Sender: TObject);
begin
  FirstSwatch.Color := SetRGBValues(edtRFirst.AsInteger, edtGFirst.AsInteger, edtBFirst.AsInteger);
end;

procedure TGradientDialog.ColorChange(Sender: TObject);
begin
  if FUpdate then Exit;

  RenderGradient;
  GradientChange(nil);
end;

procedure TGradientDialog.SecondChange(Sender: TObject);
begin
  SecondSwatch.Color := SetRGBValues(edtRSecond.AsInteger, edtGSecond.AsInteger, edtBSecond.AsInteger);
end;

procedure TGradientDialog.GradientChange(Sender: TObject);
var
  I: Integer;
  A: TColorArray;
begin
  if FUpdate then Exit;

  Gradient.ClearColors;

  A := GetGradientColors(FirstSwatch.Color, SecondSwatch.Color, TByteVal(Round(edtSteps.Value)));

  if cbReverse.Checked then // <-- exceptions here
  begin
    for I := High(A) downto 0 do
      Gradient.AddColor('', FormatColor(A[I], cfePascal), False);
    ;
  end
  else
  begin
    for I := 0 to High(A) do
      Gradient.AddColor('', FormatColor(A[I], cfePascal), False);
    ;
  end;

  Gradient.Invalidate;
end;

end.
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

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

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 01: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
 
#19

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 07: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.184 Beiträge
 
Delphi 12 Athens
 
#20

AW: My Delphi 2010 is sick

  Alt 9. Jul 2012, 09: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
$2B or not $2B
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      


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 00:06 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