Tworzę formę na niej panel i kilka innych komponentów. Wszystko jest pięknie do momentu w którym próbuję zwolnić utworzoną dynamicznie formę, bez względu czy użyję polecenia
X.Free
czy FreeAndNil(X)
, wyskakuje błąd <b>Naruszenie Praw Dostępu...</b> Poradziłem sobie poprzez obsługę tego błędu ale to nie jest wyjście z sytuacji chciałbym się dowiedzieć dlaczego tak się dzieje. W ostateczności mogę użyć poleceń Show/Hide ale wolałbym za każdym razem zwalniać zajętą pamięć.
P.s. Dla tych którzy będą mnie odsyłać do przeszukania forum zrobiłem to i nie znalazłem odpowiedzi. :|
A tak to wygląda :
```delphi
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure btnCilck(Sender: TObject);
end;
var
Form1: TForm1;
x: TForm;
p: TPanel;
l1,l2: TLabeledEdit;
st: TLabel;
b1,b2: Tbevel;
btn: TBitbtn;
implementation
{$R *.dfm}
Procedure Tform1.btnCilck(Sender: TObject);
Begin
Application.MessageBox('Kliknięcie','informacja',0);
Try
FreeAndNil(X);
Except
on E : Exception do MessageBox(0,(PAnsiChar(E.Message)),'Błąd...',MB_ICONERROR);
End;
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
Try
X := TForm.Create(application);
p := Tpanel.Create(x);
b1 := TBevel.Create(p);
b2 := TBevel.Create(p);
st := TLabel.Create(p);
l1 := TLabeledEdit.Create(p);
l2 := TLabeledEdit.Create(p);
btn := TBitBtn.Create(p);
//FORMA
X.Name := 'FullScreen';
X.BorderStyle := bsNone;
X.FormStyle := fsStayOnTop;
X.Top := 0;
X.Left := 0;
X.Width := Screen.Width;
X.Height := Screen.Height;
X.WindowState := wsMaximized;
//PANEL
P.Width := 435;
P.Height := 361;
P.Left := (X.Width div 2) - (P.Width div 2);
P.Top := (X.Height div 2) - (P.Height div 2);
P.BorderStyle := bsSingle;
p.Parent := x;
//RAMKA
b1.Left := 29;
b1.Top := 22;
b1.Width := 374;
b1.Height := 117;
b1.Style := bsLowered;
b1.Shape := bsBox;
b1.Parent := p;
//LABEL
st.Left := 32;
st.Top := 24;
st.Width := 369;
st.Height := 113;
st.AutoSize := False;
st.WordWrap := True;
st.Caption := '; The WARNINGS ISSUED below informs you if any warnings' +
' were reported. If so, the ; plug-in(s) has invoked ' +
'functions that can not be recorded to this file. In this' +
' ; case, this REG file might not work as expected. ';
st.Alignment := taCenter;
st.Parent := p;
// RAMKA DOLNA
b2.Left := 29;
b2.Top := 168;
b2.Width := 173;
b2.Height := 145;
b2.Style := bsLowered;
b2.Shape := bsBox;
b2.Parent := p;
//EDIT - LOGIN
l1.EditLabel.Caption := 'Login';
l1.Left := 40;
l1.Top := 192;
l1.Width := 153;
l1.Height := 19;
l1.Ctl3D := False;
l1.BevelInner := bvNone;
l1.BevelKind := bkSoft;
l1.Parent := p;
//EDIT-HASŁO
l2.EditLabel.Caption := 'Hasło';
l2.Left := 40;
l2.Top := 240;
l2.Width := 153;
l2.Height := 19;
l2.Ctl3D := False;
l2.BevelInner := bvNone;
l2.BevelKind := bkSoft;
l2.Parent := p;
//BUTTONIK
btn.Left := 48;
btn.Top := 272;
btn.Width := 129;
btn.Height := 25;
btn.Kind := bkAll;
btn.Caption := 'Odblokuj';
btn.Parent := p;
btn.OnClick := btnCilck;
finally;
X.Show;
end;
end;
end.
A może coś gdzieś robię źlle??