AGB  ·  Datenschutz  ·  Impressum  







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

AccessViolation bei TLabel.Create(nil)

Ein Thema von diComm · begonnen am 26. Aug 2009 · letzter Beitrag vom 1. Sep 2009
Antwort Antwort
diComm

Registriert seit: 26. Jan 2005
68 Beiträge
 
#1

Re: AccessViolation bei TLabel.Create(nil)

  Alt 26. Aug 2009, 11:14
hmm... kann eigentlich alle 4 Punkte mit ziemlicher Sicherheit ausschliessen.
Würde dann der Fehler nicht sowieso beim Zugriff auf das nichtvorhandene Objekt auftreten?
Der Fehler kommt eben leider genau auf dem Create eines Labels, und dass, nachdem der Befehl vorher schon ein paarmal funktioniert hat in einer Schleife, wo auch alle andern Befehele vorher schon mehrmals ohne Fehler durchlaufen...

Aber danke trotzdem


Hier der Code

Delphi-Quellcode:
function TLohnartsForm.PushPanel(AScrollBox : TScrollBox): TPanel;

  function getNewPanel(aParent : TScrollBox) : TPanel;
  var
    i : integer;
    aLabel : TLabel;
  begin
    Result := TPanel.Create(nil);
    With Result Do
    Begin
      Name := Format('Panel_%s_%d',[AScrollBox.Name,AScrollBox.ControlCount]);
      Caption := '';
      Parent := Self;
      Left := 8;
      Top := 312;
      Width := 425;
      Height := 25;
      TabOrder := 2;
      Visible := False;
    End; { With }
    For i := 0 To 5 Do
    Begin
      Try
        aLabel := TLabel.Create(Result);
      Except
        Break;
      End;

      With aLabel Do
      Begin
        Name := Format('Label_%s_%d_%d',[AScrollBox.Name,AScrollBox.ControlCount,i]);
        Left := getLeft(i);
        Top := 6;
        Width := 44;
        Height := 13;
        Parent := Result;
        If AScrollBox.ControlCount = 0 Then
        Begin
          Caption := getCaption(i);
          Font.Charset := DEFAULT_CHARSET;
          Font.Color := clWindowText;
          Font.Height := -11;
          Font.Name := 'Tahoma';
          Font.Style := [fsBold];
          ParentFont := False;
        End
        Else
        Begin
          Caption := '---';
        End; { If }
      End; { With }
    End; { For }
  end;

var
  I : Integer;
begin
  //Application.ProcessMessages;
  Result := getNewPanel(AScrollBox);

  With Result Do
  Begin
    Parent := AScrollBox;
    Height := Item_Height;
    Top := AScrollBox.ControlCount * Height;
    Align := alTop;
    Visible := True;
    ParentBackground := False;

    For I := 0 To Pred(ControlCount) Do
    Begin
      With Controls[I] Do
      Begin
        Top := (Result.Height - Controls[I].Height) Div 2;
        AutoSize := False;
        If I = 0 Then
        Begin
          Width := AScrollBox.ClientWidth - (5 *
            (Item_Text_Width + Item_Margin)) - (Item_Margin * 3);
          Anchors := [akTop,akLeft,akRight];
          Left := Item_Margin;
        End
        Else
        Begin
          Left := ((AScrollBox.ClientWidth - Item_Margin) -
            ((ControlCount - I) * (Item_Text_Width + Item_Margin)));
          Width := Item_Text_Width;
          Anchors := [akTop,akRight];
        End; { Else }
      End; { With }
    End; { For }
  End; { With }
end;
Die Methode wird in eriner Schleife aufgerufen.
Der Fehler tritt in der Zeile aLabel := TLabel.Create(Result); auf, allerdings nicht im ersten durchgeng der For schleife... und auch nciht, wenn ich die ganze Methode das erste mal aufrufe, erst im dritten mal.
  Mit Zitat antworten Zitat
Antwort Antwort


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:24 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 by Thomas Breitkreuz