How to Clear a Form in the IDE and more...

Hello,

I have a very wired need where in I want to perform following in the IDEEngine:
  1. Clear the content of the active Form. Here by clear content I mean remove all the controls from the active Form (.sfm) and also all the code from its associated module (.psc).

  2. Want to give facility to user to borrow a form and its controls with their layout from withing the exe at run time. Here the user can copy the layout of say Purchase Order Form (which is actually designed in Delphi) with all the controls and with the same layout. This feature will help me give flexibility to users to replace the built in forms by creating their own forms visually and writing their own logic.
How can we Clear a Form and associated code and also add controls programmatically to an active Form in the IDEEngine?

Regards,

Yogesh

With IDEEngine.Files you have access to all files in the project. Each TIDEProjectFile object in that collection has a Form property (of type TComponent, but represents the form instance) and Script property (of type TatScript).

Simply directly manipulate this objects, creating/destroying objects in the form, or changing Script.SourceCode property.


Thanks for the info. But I already know that.

But I am not able to detect as to which Module/Form is active in the IDE. How can I detect that in the first place?

When adding a form I have to add complete structure like this:

object Form2: TScriptForm
  Caption = 'Form2'
  ClientHeight = 296
  ClientWidth = 444
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  SaveProps.Strings = (
    'Visible=False')
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 8
    Top = 8
    Width = 241
    Height = 49
    Caption = 'Panel1'
    TabOrder = 8
  end
end


Here is the code that I am using at present for testing. This is hard coded at present.

IDEEngine1.Files[1].LoadFormFromString(FormContent);
IDEEngine1.Designer.Update;


Here again the IDE is not getting update properly. I have to switch to another module or form and back to see the updates. How to solve this problem?

Regards,

Yogesh

A simple code like this works fine:




  if IDEEngine1.ActiveFile.Form <> nil then
    with TButton.Create(IDEEngine1.ActiveFile.Form) do
      Parent := TWinControl(Owner);