Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Tabs

Status
Not open for further replies.

maslar

Programmer
Joined
Sep 3, 2003
Messages
5
Location
US
Hello All,

I want to create an application that allows the user to open multiple tabs, each displaying the same controls, but with different data. I started with a new frame, upon which I placed the required controls. I then created a form and put a PageControl on it. I then created a button on the form that calls this procedure:

procedure TFormMain.openDoc(Sender: TObject);
var
ts: TTabSheet;
doc: TFrameDoc;
begin
ts := TTabSheet.Create(Self);
ts.Caption := 'New Tab';
ts.PageControl := PageControl1;
doc := TFrameDoc.Create(Self);
doc.Parent := ts;
end;

When I click the button once, it works great. The new tab page is added, including the TFrameDoc. But when I click the button a second time, I get an error saying "A component named FrameDoc already exists." Am I close, or am I doing this all wrong? I am new to Delphi, but have done lots of work with similar tools like Powerbuilder. With PB, I can build a custom frame-like object called a UserObject, and can create as many as I want at runtime. How can I accomplish this in Delphi?

Thanks very much.
 
Try giving the component that you create a unique name. Something like:
Code:
var
  SheetNo: integer;
begin
  SheetNo := 1;
  ...
  ...
  inc ( SheetNo );
  ts := TTabSheet.Create(Self);
  ts.Name := 'Sheet' + IntToStr(SheetNo);
  ts.Caption := 'New Tab';
  ...
end;
I haven't tried this code out so there may be some typos but each created component must be given a unique name.

Andrew
 
Thanks. You solved my problem! I also had to do this:

doc.Name := 'Doc' + IntToStr(SheetNo);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top