I am working on my own MSN client/bot and when someone contacts me or i contact them I make a new TabSheet that contains 2 labels, a listbox and a button.
Code that I use:
The button on here is to free the tabsheet. The code that I use to free the tabsheet:
When I click the button I get an Access Violation and I don't understand why that is. Anyone got any ideas?
BobbaFet
Code that I use:
Code:
// Make a new tabsheet //
procedure TForm1.MakeNewTabSheetForNewUser(MSNUser: TMSNUser);
var mySheet: TTabSheet;
var myLabel1, myLabel2: TLabel;
var myListBox: TListBox;
var myButton: TButton;
var MakeANewPage: Boolean;
var i: integer;
begin
MakeANewPage := True;
for i := 0 to PageControl1.PageCount - 1 do
begin
if PageControl1.Pages[i].Name = RemoveAtAndDotFromEmail(MSNUser.Passport) then
begin
MakeANewPage := False;
Break;
end;
end;
if MakeANewPage then
begin
mySheet := TTabSheet.Create(PageControl1);
myLabel1 := TLabel.Create(mySheet);
myLabel2 := TLabel.Create(mySheet);
myListBox := TListBox.Create(mySheet);
myButton := TButton.Create(mySheet);
with mySheet do
begin
Parent := PageControl1;
PageControl := PageControl1;
Name := RemoveAtAndDotFromEmail(MSNUser.Passport);
Caption := MSNUser.Displayname;
Visible := True;
TabVisible := True;
OnShow := thisTabSheetShow;
end;
with myLabel1 do
begin
Parent := mySheet;
Caption := MSNUser.Displayname + '''s email: ';
Top := lbTemplate.Top;
Left := lbTemplate.Left;
Visible := True;
Name := 'label' + IntToStr(PageControl1.PageCount);
end;
with myLabel2 do
begin
Parent := mySheet;
Caption := MSNUser.Passport;
Name := 'lb' + RemoveAtAndDotFromEmail(MSNUser.Passport);
Top := lbTemplateEmail.Top;
Left := lbTemplateEmail.Left;
Visible := True;
end;
with myListBox do
begin
Parent := mySheet;
Visible := True;
Name := 'lib' + RemoveAtAndDotFromEmail(MSNUser.Passport);
Left := libTemplate.Left;
Top := libTemplate.Top;
Width := libTemplate.Width;
Height := libTemplate.Height;
end;
with myButton do
begin
Parent := mySheet;
Visible := True;
OnClick := thisButton;
Caption := 'X';
Name := 'bt' + RemoveAtAndDotFromEmail(MSNUser.Passport);
Top := btTemplate.Top;
Left := btTemplate.Left;
Height := btTemplate.Height;
Width := btTemplate.Width;
end;
PageControl1.ActivePage := mySheet;
end;
end;
The button on here is to free the tabsheet. The code that I use to free the tabsheet:
Code:
procedure TForm1.thisButton(Sender: TObject);
var i: integer;
var thisTabsheet: TTabSheet;
begin
thisTabsheet := ((Sender as TButton).Parent as TTabSheet);
for i := thisTabsheet.ControlCount - 1 downto 0 do
thisTabsheet.Controls[i].Free;
thisTabsheet.Free;
end;
When I click the button I get an Access Violation and I don't understand why that is. Anyone got any ideas?
BobbaFet
Code:
if not Programming = 'Severe Migraine' then
ShowMessage('Eureka!');