Hi,
I have been spending the last few weeks working on a bit of software and have now run into a stumbling block that I can't seem to get past. I was wandering if you might be able to help.
I have a form that has a PageControl on it.
I dynamicly create tabsheets using this:
procedure TForm1.NewCharClick(Sender: TObject);
var ts: TTabSheet;
i : integer;
begin
ts := TTabSheet.Create(Self);
With ts Do
Begin
Caption := 'NPC';
PageControl := PageControl1;
With TForm2.Create( Self ) Do
Begin
Parent := ts;
Visible := True;
Align := alClient;
Windows.SetParent( handle, ts.handle );
End;
End;
Pagecontrol1.ActivePage := ts;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PageControl1.OwnerDraw:=true;
end;
As you can see Form2 is attached to the tabsheet.
On Form 2 I dynamically create a TComboBox and a
TCBox = class(TCombobox)
private
procedure CBoxOnChange(Sender:TObject);
public
constructor create(AOwner:TComponent; iTop, iLeft, iWidth, iHeight:integer);
destructor Destroy;
end;
var
Form2: TForm2;
New_CB_1 : TCBox;
constructor TCBox.create(AOwner:TComponent; iTop, iLeft, iWidth, iHeight:integer);
begin
inherited create(AOwner);
parent:=TWinControl(AOwner);
with Self do
begin
top:=iTop;
left:=iLeft;
width:=iWidth;
height:=iHeight;
visible:=true;
enabled:=true;
OnChange:=CBoxOnChange;
Items.add('Line1');
Items.add('Line2');
end;
end;
destructor TCBox.destroy;
begin
end;
Procedure TForm2.CreateParams( Var Params: TCreateParams );
begin
Inherited CreateParams( Params );
Params.Style := Params.Style or WS_CHILD or WS_CLIPSIBLINGS;
end;
procedure TCBox.CBoxOnChange(Sender: TObject);
begin
Form2.lOutput.caption := screen.ActiveControl.Name;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
New_CB_1 := TCBox.create(Panel1, 30, 10, 100, 20);
end;
I tested Form2 as a stand alone program and it works fine.
But used here, when the form is dynamically created, I get errors when I try to envoke the onchange events [Access violation at address ......].
Do you have any ideas?
Any help would be appreciated.
Colin
I have been spending the last few weeks working on a bit of software and have now run into a stumbling block that I can't seem to get past. I was wandering if you might be able to help.
I have a form that has a PageControl on it.
I dynamicly create tabsheets using this:
procedure TForm1.NewCharClick(Sender: TObject);
var ts: TTabSheet;
i : integer;
begin
ts := TTabSheet.Create(Self);
With ts Do
Begin
Caption := 'NPC';
PageControl := PageControl1;
With TForm2.Create( Self ) Do
Begin
Parent := ts;
Visible := True;
Align := alClient;
Windows.SetParent( handle, ts.handle );
End;
End;
Pagecontrol1.ActivePage := ts;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PageControl1.OwnerDraw:=true;
end;
As you can see Form2 is attached to the tabsheet.
On Form 2 I dynamically create a TComboBox and a
TCBox = class(TCombobox)
private
procedure CBoxOnChange(Sender:TObject);
public
constructor create(AOwner:TComponent; iTop, iLeft, iWidth, iHeight:integer);
destructor Destroy;
end;
var
Form2: TForm2;
New_CB_1 : TCBox;
constructor TCBox.create(AOwner:TComponent; iTop, iLeft, iWidth, iHeight:integer);
begin
inherited create(AOwner);
parent:=TWinControl(AOwner);
with Self do
begin
top:=iTop;
left:=iLeft;
width:=iWidth;
height:=iHeight;
visible:=true;
enabled:=true;
OnChange:=CBoxOnChange;
Items.add('Line1');
Items.add('Line2');
end;
end;
destructor TCBox.destroy;
begin
end;
Procedure TForm2.CreateParams( Var Params: TCreateParams );
begin
Inherited CreateParams( Params );
Params.Style := Params.Style or WS_CHILD or WS_CLIPSIBLINGS;
end;
procedure TCBox.CBoxOnChange(Sender: TObject);
begin
Form2.lOutput.caption := screen.ActiveControl.Name;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
New_CB_1 := TCBox.create(Panel1, 30, 10, 100, 20);
end;
I tested Form2 as a stand alone program and it works fine.
But used here, when the form is dynamically created, I get errors when I try to envoke the onchange events [Access violation at address ......].
Do you have any ideas?
Any help would be appreciated.
Colin