0

Hey guys I have two Form2's from Form1, so I wanted to edit the two Form2's I can do it with c++

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

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

any idea how to convert it to delphi code ?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
user1979304
  • 91
  • 1
  • 6

1 Answers1

1

Like this:

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;

Or this:

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;

Depending on your Delphi version.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770