You cannot do what you want with a with
statement. There is no way to name the object that is the subject of a with statement.
Use a local variable instead. For example:
var
Panel1: TPanel
Button1: TButton;
....
Panel1 := TPanel.Create(Form1);
Panel1.Parent := Form1;
Button1 := TButton.Create(Panel1);
Button1.Parent := Panel1;
As an added benefit you get to remove these with
statements that are a scoping blight on any code.