简体   繁体   中英

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM