Script in MDI forms

Hi...

I??m using the Method AddForm(Self) in the OnCreate event in the MDI forms.

In The Main Form:
uses UDataMod;

procedure TMainForm.Create(Sender: TObject);
begin
  fsGlobalUnit.AddForm(DataMod); // UDataMod.pas, TDataModule... access to db
end;

Now, the script is executed in the MDI child Form1, who references the object
DataMod, added previously, works ok...
procedure TForm1.OnCreate(Sender: TObject);
begin
  fsGlobalUnit.AddForm(Self); // Works ok, now i can acess the form 
   // and his components.
  
  fsScript1.Run; // Execute the script in local MDI...
end;

The form is destroyed in the OnClose event by using:
procedure TForm1.OnClose(Sender: TObject; Action: TCloseAction);
begin
  //fsGlobalUnit.Remove(Form1); 
  //fsGlobalUnit.RemoveItens(Form1);
  // i??ve tried to put the Remove methods BEFORE free the Form1, but doesn??t
  // works, in next time he gave me an error.
  Form1 := nil; // 
  Action := caFree; 
  fsGlobalUnit.Remove(Form1); // doesn??t happened anything...
  fsGlobalUnit.RemoveItens(Form1); // Remove the form and another controls, like 
  // Datamodules added by main form.
end;

When i try to create the Form1 Again, the DataMod doesn??t exists anymore, in the fsGlobalUnit items. How To Proceed to AddForm and RemoveForm correctly, in these MDI forms ?

Comments

  • edited 9:20PM
    AddForm can be used only one time. You can't remove that form because the AddForm method touchs the class tree.
  • edited 9:20PM
    Well, calling AddForm just on time works only in the first time i call the script. When i close the form and open it again (by creating it self) i??m not adding it to fsGlobalUnit anymore. How to improve this with MDI childs, so ? Is there any way ?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.