从Form1编辑两个Form2

时间:2013-07-07 11:10:14

标签: delphi delphi-7 delphi-xe

嘿伙计我有Form1的两个Form2,所以我想编辑两个Form2 我可以用c ++

来做
       for each(Form ^ mForm in Application::OpenForms )
        {

            myForm2= dynamic_cast<Form2^>(mForm);
            if(myForm2 != nullptr) 
                //do something with Form2
        }

任何想法如何将其转换为delphi代码?

1 个答案:

答案 0 :(得分:1)

像这样:

var
  theForm: TForm;
  myForm2: Form2;
begin
  for theForm in Screen.Forms do
  begin
    if theForm is Form2 then
    begin
      myForm2 := Form2(theForm);
      //do something with myForm2...
    end;
  end;
end;

或者这个:

var
  theForm: TForm;
  myForm2: Form2;
  I: Integer;
begin
  for I := 0 to Screen.Forms.Count-1 do
  begin
    theForm := Screen.Forms[I];
    if theForm is Form2 then
    begin
     myForm2 := Form2(theForm);
      //do something with myForm2...
    end;
  end;
end;

取决于您的Delphi版本。