AGB  ·  Datenschutz  ·  Impressum  







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

AV bei frmSettings.ComponentCount

Ein Thema von xZise · begonnen am 1. Aug 2006 · letzter Beitrag vom 1. Aug 2006
Antwort Antwort
Seite 1 von 2  1 2      
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#1

AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:26
Ich bekomme eine AV in dieser Zeile:
for i := 0 to frmSettings.ComponentCount - 1 do begin Code:

Delphi-Quellcode:
procedure TfrmSettings.FormCreate(Sender: TObject);
var Ini, Skin : TIniFile;
    s : String;
    BackgrndFade : TColor;
    i : Integer;
begin
  Ini := TIniFile.Create(ExtractFilePath(application.exename) + 'settings.ini');
  try
    s := Ini.ReadString('Settings', 'Skin', ExtractFilePath(Application.ExeName) + 'skins\blue.dpsf');
  finally
    Ini.Free;
  end;

  if FileExists(s) then begin
    Skin := TIniFile.Create(s);
    try
      for i := 0 to frmSettings.ComponentCount - 1 do begin <:=-------- Diese Zeile
        if frmSettings.Components[i] is TXiPanel then begin
          (frmSettings.Components[i] as TXiPanel).ColorFace := StringToColor(Skin.ReadString('Backgrnd', 'Face', '$00FE9741'));
          if (frmSettings.Components[i] as TXiPanel).Name <> 'xiBgthen
            (frmSettings.Components[i] as TXiPanel).ColorGrad := StringToColor(Skin.ReadString('Backgrnd', 'Face', '$00FE9741'))
          else
            xiBg.ColorGrad := StringToColor(Skin.ReadString('Backgrnd', 'Grad', 'clSkyBlue'));

        end;
      end;


{      BackgrndFade := StringToColor(Skin.ReadString('Backgrnd', 'Face', '$00FE9741'));
      xiBg.ColorFace := BackgrndFade;
//      xiInUse.ColorFace := BackgrndFade;
    //  xiInUse.ColorGrad := BackgrndFade;
  //    xiSets.ColorFace := BackgrndFade;
      //xiSets.ColorGrad := BackgrndFade;

      xiBg.ColorGrad := StringToColor(Skin.ReadString('Backgrnd', 'Grad', 'clSkyBlue'));}

      lSkinName.Caption := Skin.ReadString('Skin', 'Name', '<unnamed>');
    finally
      Skin.Free;
    end;
    eSkinPath.Text := s;

  end else begin
    lSkinName.Caption := 'Blue';
    eSkinPath.Text := ExtractFilePath(Application.ExeName) + 'skins\blue.dpsf';
    Showmessage('Skinfile not found!');
  end;
end;
So sieht sie aus:
Code:
---------------------------
Debugger Exception Notification
---------------------------
Project DarkPlayerII.exe raised exception class EAccessViolation with message 'Access violation at address 0041A778 in module 'DarkPlayerII.exe'. Read of address 00000010'. Process stopped. Use Step or Run to continue.
---------------------------
OK  Help  
---------------------------
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:35
Hallo,

lass das frmSettings mal komplett weg.
Wahrscheinlicb erzeugst du dein Formular ohne diese Variable.
Die wäre dann NIL, und damit bekommst du dann deine Schutzverletzung.

Heiko
Heiko
  Mit Zitat antworten Zitat
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#3

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:40
Zitat von hoika:
Wahrscheinlicb erzeugst du dein Formular ohne diese Variable.
Also ich erzeuge sie so:
with TfrmSettings.Create(self) do liegt das vielleicht daran?

[edit] Also so funktionierts (mit weglassen), aber warum funktionierts nicht andersherum?[/edit]
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#4

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:42
Ja. Wenn dann Self.xyz, aber nicht aus der Klasse auf die globale Variable zugreifen, die eigentlich das Objekt selbst beinhalten sollte (oder es wie hier eben nicht tut ^^)

@edit: weil du die globale Variable frmSetting nicht belegst, sondern nur den Konstruktor usführt, und du somit nur auf zwei Wege auf das Objekt zugreifen kannst: 1. innerhalb der Klasse z.B. mit Self und 2. innerhalb des with Blicks.
  Mit Zitat antworten Zitat
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#5

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:45
Also statt self USettings.TfrmSettings ?
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#6

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:47
NEIN

Also:
statt frmSettings.ComponentCount das:Self.ComponentCount da frmSettings nicht belegt ist. Da man das Self auch weglassen kann, geht es auch einfach so:ComponentCount Jetzt alles ok?
  Mit Zitat antworten Zitat
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#7

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:49
Ja das ist schon klar... Ich meinte beim Create!
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
Benutzerbild von jfheins
jfheins

Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
 
#8

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:53
Aso ... das ist ein anderes Paar Schuhe ...

wenn du es so erzeugst:with TfrmSettings.Create(self) do dann ist das Objekt, in dessen Methode dies geschieht, der Oner. der Owner gibt das Objekt wieder frei. Der Owner ist über die Property Owner abrufbar.
Die globale Variable frmSettings hat nix damit zu tun. Du könntest die Variable auch entfernen, dann hast du solche Probleme nichtmehr
  Mit Zitat antworten Zitat
Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#9

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 12:55
Ich habe nur gefragt, weil es ja diese zuweisung bei "application.CreateForm(X,Y)" gibt. Aber okay Ich frag mich gerade wozu man die überhaupt braucht...
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#10

Re: AV bei frmSettings.ComponentCount

  Alt 1. Aug 2006, 14:08
Hallo,

das Application.CreateForm erzeugt die Forms schon beim Start des
Programms (FormCreate wird also für jedes Form schon erzeugt).

Vorteil:
Die Forms können mit FormVar.ShowModal oder .Show sofort (schnell) angelegt werden.

Nachteil:
Deer Start dauert länger, Ressourcen werden verbraten.


Bei mir wird nur das Hauptform erzeugt.
Die globalen FormVars lösche ich.
Forms erzeuge ich immer in der folgenden Art:

Delphi-Quellcode:
procedure ExecuteForm_PEP__Main(AnOwner: TComponent);
var
  Form: TForm_PEP__Main;
begin
  try
    Form:= TForm_PEP__Main.Create(AnOwner);
    try
      Form.ShowModal;
    finally
      Form.Free;
    end;
  except
    on E: Exception do MBError(E.message);
  end;
end;
Die Variable ist hier unnütz, aber oft übergebe ich den Forms ja noch was
und speichere das in einer internen Form-Variable.


Heiko

[edit=SirThornberry]Delphi-Tags ergänzt - nächstes mal bitte selbst machen - Mfg, SirThornberry[/edit]
Heiko
  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 00:32 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