S bossen
S bossen

Reputation: 89

How to Get a value from a form in side a PageControl

Here is how I am creating My PageControl.

PageCtrlSub := TPageControl.Create(Self);
PageCtrlSub.Parent := GroupSub;
PageCtrlSub.Align := alClient;
SubFormCnt := 0;
TblOdSub.First;
while not TblOdSub.Eof do
  begin
    SubPartNo := TblOdSub.FieldByName('sub_part_no').AsString;
    AddNewSubTab(SubPartNo,Prc1Rs);
    TblOdSub.Next;
  end;

Here is how I am Creating my TabSheet and Form on the tabSheet.

procedure TFrmSub.AddNewSubTab(PartNo : String; PrcRs : TPriceRec);
  var
    i : Integer;
  begin
    inc(SubFormCnt);
    TabSheet := TTabSheet.Create(PageCtrlSub);
    TabSheet.Caption := 'Sub '+ intToStr(SubFormCnt);
    TabSheet.PageControl := PageCtrlSub;
    Form := TFrmSubExchange.Create(Self);
    Form.Name := 'SForm' + IntToStr(SubFormCnt);
    Form.Parent := TabSheet;
    for i := 0 to Componentcount-1 do
      begin
        if (Components[i] is TFrmSubExchange) and (Components[i].Name = 'SForm' + IntToStr(SubFormCnt)) then
          TFrmSubExchange(Components[i]).DataChangedSub(PartNo, PrcRs);
      end;
    Form.Show;
end;

I have a TCaption on each form that is created. When the user changes tab and press a button I need to know the text stored in the TCaption.caption property on the form of the active tab? Thanks in Advance

Upvotes: 1

Views: 213

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597941

Without seeing the DFM for TFrmSubExchange, this is just a guess, but you can try something like this:

procedure TFrmSub.SomeButtonClick(Sender: TObject);
var
  s: string;
begin
  s := (PageCtrlSub.ActivePage.Controls[0] as TFrmSubExchange).Caption1.Caption;
  ...
end;

Upvotes: 1

Related Questions