I am writing an application like this:
There is a main form with a PageControl on it, In the Page Control I create Tabsheets, In the Tabsheets, forms are placed.
This helps because the user can create one type of form more than once, like a standard pdf viewer opened in more than one tab, but displaying different data, in essence its the same form.
This works very well and is very useful! Unfortunately something important isn't working, this is the problem:
This code will work fine:
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := 'Hello';
end;
The caption will change, however, if I would like to call a method instead, like this:
Procedure changeLabel(str : String);
Begin
Form1.Label1.Caption := str;
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
changeLabel('Hello');
end;
I get an access violation at Form1.Label1.Caption := str; in the procedure
Here is how I created the form:
procedure TfrmPage.CDMA1Click(Sender: TObject);
var
TabSheet: TTabSheet;
frmTest : TForm;
begin
TabSheet := TTabSheet.Create(PageControl1);
TabSheet.Caption := 'kjklhhj';
TabSheet.PageControl := PageControl1;
frmTest := TForm1.Create(Nil);
frmTest.Show;
frmTest.Parent := TabSheet;
end;
I did everything as everyone said here: another stackoverflow question
My Question, how can the newly created form, pinned to the Tabsheet, access its own procedures without throwing exceptions? Another piece that might be important: When I have delphi Auto-Create the form, theres no access violation but the method does nothing to the form, so I think the procedure might be changing things on the wrong form, one thats not created yet (which gives AV), and not to the one i just created, or the application is not calling the method on my new form, but calling one somewhere where that form isn't created yet.
If I auto-create the form, calling the procedure probably changes the label on the form that was created when the application started and not the new form..
Any help would be appreciated, as I've been googling for hours now with no real help to this problem
Thanks in advance :)