1

i created dynamic tabsheet in page control , and then each page needs to host a frame with several component like Tedit and etc . these Tedit in my frame host data from an ini file . if i do my tabsheet static it works ! but i need to do my tabsheet dynamic ... i tried to create a frame but when i put in my loop i get error

how can i do it ?

thanks !

unit DlgXRechnung;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Xml.xmldom,
  Xml.XMLIntf, Vcl.Buttons, Xml.XMLDoc, IniFiles, Vcl.ComCtrls;

type
  TDlg_XRechnung = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    X_Rechnung: TXMLDocument;
    Memo_XML: TMemo;
    Btn_Laden: TBitBtn;
    OpenDialog_Datei: TOpenDialog;
    Panel5: TPanel;
    Label1: TLabel;
    Edit_LeitwegeID: TLabeledEdit;
    Edit_Bestellnummer: TLabeledEdit;
    Edit_Projektreferenz: TLabeledEdit;
    Edit_Vertragsnummer: TLabeledEdit;
    Edit_Rechnungsnummer: TLabeledEdit;
    Edit_Rechnungsdatum: TDateTimePicker;
    Label2: TLabel;
    Label3: TLabel;
    Edit_Leistungsdatum: TDateTimePicker;
    Edit_Bemerkung: TMemo;
    Label4: TLabel;
    Btn_XML_erstellen: TBitBtn;
    Btn_Close: TBitBtn;
    Panel6: TPanel;
    Label5: TLabel;
    Edit_Rechnungsersteller_Name: TLabeledEdit;
    Edit_Rechnungsersteller_Adresse: TLabeledEdit;
    Edit_Rechnungsersteller_PLZ: TLabeledEdit;
    Edit_Rechnungsersteller_UST_ID: TLabeledEdit;
    Edit_Rechnungsersteller_Ort: TLabeledEdit;
    Edit_Rechnungsersteller_Land: TLabeledEdit;
    Edit_Rechnungsersteller_Firmenbuch: TLabeledEdit;
    Edit_Rechnungsersteller_Steuerart: TLabeledEdit;
    GroupBox1: TGroupBox;
    Edit_Waehrung_Rechnung: TLabeledEdit;
    Edit_Waehrung_UST: TLabeledEdit;
    Panel7: TPanel;
    Label6: TLabel;
    Edit_Rechnungsempfänger_Name: TLabeledEdit;
    Edit_Rechnungsempfänger_Adresse: TLabeledEdit;
    Edit_Rechnungsempfänger_PLZ: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    Edit_Rechnungsempfänger_Ort: TLabeledEdit;
    Edit_Rechnungsempfänger_Land: TLabeledEdit;
    LabeledEdit7: TLabeledEdit;
    LabeledEdit8: TLabeledEdit;
    PC_Positionen: TPageControl;
    procedure Btn_LadenClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Btn_XML_erstellenClick(Sender: TObject);
    procedure Btn_CloseClick(Sender: TObject);
    procedure PC_PositionenChange(Sender: TObject);
  private
    INIDateiname : string;
    INIDatei : TIniFile;
    PDFDatei : string;
    XRechnungDatei : string;
    Version : integer;
    DebugMode : integer;
    AnzahlPositinen : integer;
    procedure INIDatei_einlesen;
    procedure XML_erstellen;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Dlg_XRechnung: TDlg_XRechnung;

implementation

{$R *.dfm}
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.Btn_CloseClick(Sender: TObject);
begin
  Close;
end;
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.Btn_LadenClick(Sender: TObject);
begin
  if OpenDialog_Datei.Execute then
  begin
    INIDateiname := OpenDialog_Datei.FileName;
  end;
  if Trim(INIDateiname) <> '' then INIDatei_einlesen;
end;
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.Btn_XML_erstellenClick(Sender: TObject);
begin
  XML_erstellen;
end;
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.FormCreate(Sender: TObject);
begin
  INIDateiname := '';
end;
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.FormShow(Sender: TObject);
begin
  if Trim(ParamStr(1)) <> '' then
  begin
    INIDateiname := ParamStr(1);
    INIDatei_einlesen;
  end;
end;
// -----------------------------------------------------------------------------
procedure TDlg_XRechnung.INIDatei_einlesen;
var NeueSeite : TTabSheet;
  i,l: Integer;
begin
  try
    INIDatei                := TIniFile.Create(INIDateiname);
    Version                 := INIDatei.ReadInteger('INI','Version', 1);
    DebugMode               := INIDatei.ReadInteger('INI','DebugMode', 0);
    PDFDatei                := INIDatei.ReadString('PDF','PDFName', '');
    XRechnungDatei          := INIDatei.ReadString('PDF','XInvoice', '');
    Edit_LeitwegeID.Text    := INIDatei.ReadString('InvData','BT-10', '');
    Edit_Bestellnummer.Text := INIDatei.ReadString('InvData','BT-13', '');
    Edit_Projektreferenz.Text := INIDatei.ReadString('InvData','BT-11', '');
    Edit_Vertragsnummer.Text := INIDatei.ReadString('InvData','BT-12', '');
    Edit_Rechnungsnummer.Text := INIDatei.ReadString('InvData','BT-1', '');
    Edit_Rechnungsdatum.Date := INIDatei.ReadDate('InvData','BT-2', now);
    Edit_Leistungsdatum.Date := INIDatei.ReadDate('InvData','BT-9', now);
    Edit_Bemerkung.Text := INIDatei.ReadString('InvData','BT-22', '');
    Edit_Rechnungsersteller_Name.Text := INIDatei.ReadString('InvErst','BT-27', '');
    Edit_Rechnungsersteller_UST_ID.Text := INIDatei.ReadString('InvErst','BT-31', '');
    Edit_Rechnungsersteller_Adresse.Text := INIDatei.ReadString('InvErst','BT-35', '') + INIDatei.ReadString('InvErst','BT-36', '');
    Edit_Rechnungsersteller_PLZ.Text := INIDatei.ReadString('InvErst','BT-38', '');
    Edit_Rechnungsersteller_Ort.Text := INIDatei.ReadString('InvErst','BT-37', '');
    Edit_Rechnungsersteller_Land.Text := INIDatei.ReadString('InvErst','BT-40', '');
    Edit_Rechnungsempfänger_Name.Text := INIDatei.ReadString('InvEmp','BT-44','');
    Edit_Rechnungsempfänger_Adresse.Text := INIDatei.ReadString('InvEmp','BT-50', '') + INIDatei.ReadString('InvEmp','BT-51', '');
    Edit_Rechnungsempfänger_PLZ.Text := INIDatei.ReadString('InvEmp','BT-53', '');
    Edit_Rechnungsempfänger_Ort.Text := INIDatei.ReadString('InvEmp','BT-52', '');
    Edit_Rechnungsempfänger_Land.Text := INIDatei.ReadString('InvEmp','BT-55', '');

    AnzahlPositinen := INIDatei.ReadInteger('POS','AnzPos', 1);
    for i := 1 to AnzahlPositinen do
    begin
      NeueSeite := TTabSheet.Create(PC_Positionen);
      NeueSeite.PageControl := PC_Positionen;
      NeueSeite.Caption := 'Position ' + IntToStr(i);




    end;

  finally
    INIDatei.Free;
  end;
end;

maxfido
  • 45
  • 5
  • Before adding a tag, see his definition! Tag "frame" is related to Objective-C, not Delphi. Tag "TPageControl" has no watcher so is almost useless. Your question is not specific to a Delphi 10.4.2. Conclusion: use only the tag "Delphi". Please edit your question and remove unneeded tags. – fpiette Apr 06 '21 at 11:15

1 Answers1

2

First design a TFrame using the IDE (Much like you design a TForm). Add all the items such as TEdit that your need. Add the unit of the frame to the uses clause of the form's unit. When creating the frame, you need to specify an owner. You can use the same as the TabSheet you created. You should either clear the name property or set a suitable unique name for each.

Then inside the loop you use to create the TabSheet, create a new instance of the frame, assign his parent property to the TabSheet just created, then read all items values from the INI file.

By the way, read again my answer (https://stackoverflow.com/a/66943453/189103) to your previous question. It already contained all the information required.

fpiette
  • 11,983
  • 1
  • 24
  • 46
  • Should mention the frame's owner, perhaps, in case the OP is creating the frame in code? – MartynA Apr 06 '21 at 11:39
  • 1
    Also, when using dynamic `TFrame`s, you need to clear their `Name` property at runtime, or you can get errors when multiple Frames exist in the same Owner/Parent. – Remy Lebeau Apr 06 '21 at 14:52