0

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

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

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

知道如何将其转换为 delphi 代码吗?

4

1 回答 1

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 版本。

于 2013-07-07T15:34:32.497 回答