IDE Renaming Forms

I believe this is in relation to the post here (Scripter IDE Designer renaming Forms - #9 by Zorlu_Yusuf).

I think I found a way to replicate it, but of course it could just be something I'm doing wrong.

Delphi XE3, and I believe TMS Scripter is 7.16 (unsure how to check this).

Project has 2 forms, Main Form, and a custom TMS Scripter IDE. Main Form has 2 buttons (Run Script, and Edit Script).

Run Script:

var
  AUnit: TIDEProjectFile;
  TempEngine : TIDEEngine;
  TempScripter : TIDEScripter;
begin
  TempEngine := TIDEEngine.Create(Application);
  TempScripter := TIDEScripter.Create(Application);
  TempEngine.Scripter := TempScripter;
  TempEngine.DlgCloseAll;
  TempEngine.NewProject;
  TempEngine.ProjectName := 'Test Project';

  AUnit := TempEngine.NewUnit(slPascal);
  TempEngine.MainUnit := AUnit;
  AUnit.UnitName := 'Unit1';
  AUnit.Script.SourceCode.Text := 'uses '+
                                  '  Classes, Graphics, Controls, Forms, Dialogs, Unit2; '+
                                  ' '+
                                  'var '+
                                  '  MainForm: TForm2; '+
                                  'begin '+
                                  '  MainForm := TForm2.Create(Application); '+
                                  '  MainForm.Show; '+
                                  'end;';
  TempEngine.UpdateIDE(AUnit);

  AUnit := TempEngine.NewFormUnit(slPascal);
  AUnit.LoadFormFromString('object Form2: TScriptForm '+
                           ' Caption = ''Form2'' '+
                           ' ClientHeight = 356 '+
                           ' ClientWidth = 448 '+
                           ' 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'') '+
                           ' SaveEvents.Strings = ( '+
                           '   ''AdsTable1.OnCalcFields=AdsTable1CalcFields'' '+
                           '   ''Self.OnShow=Form2Show'') '+
                           ' PixelsPerInch = 96 '+
                           ' TextHeight = 13 '+
                          'end ');
  AUnit.UnitName := 'Unit2';
  AUnit.Script.SourceCode.Text := '{$FORM TForm2, Unit2.sfm} '+
                           ' '+
                           '   uses '+
                           '     Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; '+
                           ' '+
                           '   procedure Form2Show(Sender: TObject); '+
                           '   begin '+
                           '     showmessage(''hello world''); '+
                           '   end; '+
                           ' '+
                           ' '+
                           '   begin '+
                           '   end; ';

  TempEngine.UpdateIDE(AUnit);
  TempEngine.RunProject;

Edit Script

var
  Form : TFScriptIDE;
begin
  Form := TFScriptIDE.Create(nil);
  try
    Form.ShowModal;
  finally
    Form.Free;
  end;

TFScriptIDE has a FormShow

var
  ProjectFile : TIDEProjectFile;
begin
  IDEEngine1.DlgCloseAll;
  IDEEngine1.NewProject;
  IDEEngine1.ProjectName := 'TestProject';

  //has form = false
  ProjectFile := IDEEngine1.NewUnit(slPascal);
  IDEEngine1.MainUnit := ProjectFile;
  ProjectFile.UnitName := 'Unit1';
  ProjectFile.Script.SourceCode.Text := 'uses '+
                                  '  Classes, Graphics, Controls, Forms, Dialogs, Unit2; '+
                                  ' '+
                                  'var '+
                                  '  MainForm: TForm2; '+
                                  'begin '+
                                  '  MainForm := TForm2.Create(Application); '+
                                  '  MainForm.Show; '+
                                  'end;';
  IDEEngine1.UpdateIDE(ProjectFile);

  //has form = true
  ProjectFile := IDEEngine1.NewFormUnit(slPascal);
  ProjectFile.LoadFormFromString('object Form2: TScriptForm '+
                           ' Caption = ''Form2'' '+
                           ' ClientHeight = 356 '+
                           ' ClientWidth = 448 '+
                           ' 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'') '+
                           ' SaveEvents.Strings = ( '+
                           '   ''AdsTable1.OnCalcFields=AdsTable1CalcFields'' '+
                           '   ''Self.OnShow=Form2Show'') '+
                           ' PixelsPerInch = 96 '+
                           ' TextHeight = 13 '+
                          'end ');
  ProjectFile.UnitName := 'Unit2';
  ProjectFile.Script.SourceCode.Text := '{$FORM TForm2, Unit2.sfm} '+
                           ' '+
                           '   uses '+
                           '     Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; '+
                           ' '+
                           '   procedure Form2Show(Sender: TObject); '+
                           '   begin '+
                           '     showmessage(''hello world''); '+
                           '   end; '+
                           ' '+
                           ' '+
                           '   begin '+
                           '   end; ';
  IDEEngine1.UpdateIDE(ProjectFile);

A FormClose

var
  I: Integer;
begin
  for I := 0 to IDEEngine1.Files.Count - 1 do
  begin
    if IDEEngine1.Files[i].IsForm then
      Continue
    else
    begin
      IDEEngine1.ActiveFile := IDEEngine1.Files[i];
      Break;
    end;
  end;

Form2 DFM

object FScriptIDE: TFScriptIDE
  Left = 0
  Top = 0
  Caption = 'Script Editor'
  ClientHeight = 708
  ClientWidth = 954
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  OnClose = FormClose
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Splitter1: TSplitter
    Left = 201
    Top = 0
    Width = 5
    Height = 708
    Color = clMoneyGreen
    ParentColor = False
    ExplicitLeft = 121
    ExplicitTop = 49
    ExplicitHeight = 369
  end
  object Splitter2: TSplitter
    Left = 739
    Top = 0
    Width = 5
    Height = 708
    Align = alRight
    Color = clMoneyGreen
    ParentColor = False
    ExplicitLeft = 773
    ExplicitHeight = 665
  end
  object TabControl1: TTabControl
    Left = 206
    Top = 0
    Width = 533
    Height = 708
    Align = alClient
    TabOrder = 0
    Visible = False
    ExplicitHeight = 688
    object IDEMemo1: TIDEMemo
      Left = 4
      Top = 6
      Width = 525
      Height = 698
      Cursor = crIBeam
      ActiveLineSettings.ShowActiveLine = False
      ActiveLineSettings.ShowActiveLineIndicator = False
      ActiveLineSettings.ActiveLineColor = 10066380
      ActiveLineSettings.ActiveLineTextColor = clBlack
      Align = alClient
      AutoCompletion.Font.Charset = DEFAULT_CHARSET
      AutoCompletion.Font.Color = clWindowText
      AutoCompletion.Font.Height = -11
      AutoCompletion.Font.Name = 'Tahoma'
      AutoCompletion.Font.Style = []
      AutoCompletion.StartToken = '(.'
      AutoCorrect.Active = True
      AutoHintParameterPosition = hpBelowCode
      BookmarkGlyph.Data = {
        36050000424D3605000000000000360400002800000010000000100000000100
        0800000000000001000000000000000000000001000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000C0DCC000F0CA
        A6000020400000206000002080000020A0000020C0000020E000004000000040
        20000040400000406000004080000040A0000040C0000040E000006000000060
        20000060400000606000006080000060A0000060C0000060E000008000000080
        20000080400000806000008080000080A0000080C0000080E00000A0000000A0
        200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0
        200000C0400000C0600000C0800000C0A00000C0C00000C0E00000E0000000E0
        200000E0400000E0600000E0800000E0A00000E0C00000E0E000400000004000
        20004000400040006000400080004000A0004000C0004000E000402000004020
        20004020400040206000402080004020A0004020C0004020E000404000004040
        20004040400040406000404080004040A0004040C0004040E000406000004060
        20004060400040606000406080004060A0004060C0004060E000408000004080
        20004080400040806000408080004080A0004080C0004080E00040A0000040A0
        200040A0400040A0600040A0800040A0A00040A0C00040A0E00040C0000040C0
        200040C0400040C0600040C0800040C0A00040C0C00040C0E00040E0000040E0
        200040E0400040E0600040E0800040E0A00040E0C00040E0E000800000008000
        20008000400080006000800080008000A0008000C0008000E000802000008020
        20008020400080206000802080008020A0008020C0008020E000804000008040
        20008040400080406000804080008040A0008040C0008040E000806000008060
        20008060400080606000806080008060A0008060C0008060E000808000008080
        20008080400080806000808080008080A0008080C0008080E00080A0000080A0
        200080A0400080A0600080A0800080A0A00080A0C00080A0E00080C0000080C0
        200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0
        200080E0400080E0600080E0800080E0A00080E0C00080E0E000C0000000C000
        2000C0004000C0006000C0008000C000A000C000C000C000E000C0200000C020
        2000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
        2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C060
        2000C0604000C0606000C0608000C060A000C060C000C060E000C0800000C080
        2000C0804000C0806000C0808000C080A000C080C000C080E000C0A00000C0A0
        2000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C0
        2000C0C04000C0C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FDFD25252525
        2525252525252525FDFDFD2E25FFFFFFFFFFFFFFFFFFFF25FDFDFD2525252525
        2525252525252525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25B7B7B7B7
        B7B7B7B7B7B72525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25BFB7BFBF
        B7B7B7B7B7B72525FDFD9A9ABFBFBFB7BFBFB7B7B7B72525FDFDFD25BFBFBFBF
        BFB7BFBFB7B72525FDFD9A9ABFBFBFB7BFBFBFB7BFB72525FDFDFD25BFBFBFBF
        BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFB7BFBFB7B72525FDFDFD25BFBFBFBF
        BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFBFBFBFBFB725FDFDFDFD2525252525
        25252525252525FDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFD}
      BorderStyle = bsSingle
      BreakpointColor = 16762823
      BreakpointTextColor = clBlack
      ClipboardFormats = [cfText]
      CodeFolding.Enabled = False
      CodeFolding.LineColor = clGray
      Ctl3D = False
      DelErase = True
      EnhancedHomeKey = False
      Gutter.Font.Charset = DEFAULT_CHARSET
      Gutter.Font.Color = clWindowText
      Gutter.Font.Height = -13
      Gutter.Font.Name = 'Courier New'
      Gutter.Font.Style = []
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clBlack
      Font.Height = -13
      Font.Name = 'COURIER NEW'
      Font.Style = []
      HiddenCaret = False
      Lines.Strings = (
        '')
      MarkerList.UseDefaultMarkerImageIndex = False
      MarkerList.DefaultMarkerImageIndex = -1
      MarkerList.ImageTransparentColor = 33554432
      OleDropTarget = []
      PrintOptions.MarginLeft = 0
      PrintOptions.MarginRight = 0
      PrintOptions.MarginTop = 0
      PrintOptions.MarginBottom = 0
      PrintOptions.PageNr = False
      PrintOptions.PrintLineNumbers = False
      RightMarginColor = 14869218
      ScrollHint = False
      SelColor = clWhite
      SelBkColor = clNavy
      ShowRightMargin = True
      SmartTabs = False
      TabOrder = 0
      TabStop = True
      TrimTrailingSpaces = False
      UILanguage.ScrollHint = 'Row'
      UILanguage.Undo = 'Undo'
      UILanguage.Redo = 'Redo'
      UILanguage.Copy = 'Copy'
      UILanguage.Cut = 'Cut'
      UILanguage.Paste = 'Paste'
      UILanguage.Delete = 'Delete'
      UILanguage.SelectAll = 'Select All'
      UrlStyle.TextColor = clBlue
      UrlStyle.BkColor = clWhite
      UrlStyle.Style = [fsUnderline]
      UseStyler = True
      Version = '3.6.3.0'
      WordWrap = wwNone
      ExplicitHeight = 678
    end
    object IDEFormDesignControl1: TIDEFormDesignControl
      Left = 4
      Top = 6
      Width = 525
      Height = 698
      Align = alClient
      Color = clWindow
      ParentColor = False
      ExplicitHeight = 678
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 0
    Width = 201
    Height = 708
    Align = alLeft
    TabOrder = 1
    ExplicitHeight = 688
    object IDEInspector1: TIDEInspector
      Left = 1
      Top = 48
      Width = 199
      Height = 659
      Align = alClient
      Color = clBtnFace
      TabOrder = 0
      PaintStyle = psTMS
      ExplicitHeight = 639
    end
    object ObjectInspectorComboBox: TwwDBComboBox
      Left = 1
      Top = 27
      Width = 199
      Height = 21
      ShowButton = True
      Style = csDropDownList
      MapList = False
      AllowClearKey = False
      AutoDropDown = True
      DropDownCount = 8
      ItemHeight = 0
      Items.Strings = (
        'Properties'
        'Events')
      ItemIndex = 0
      Sorted = False
      TabOrder = 1
      UnboundDataType = wwDefault
      Align = alTop
    end
    object Panel1: TPanel
      Left = 1
      Top = 1
      Width = 199
      Height = 26
      Align = alTop
      TabOrder = 2
      object IDEComponentComboBox1: TIDEComponentComboBox
        Left = 0
        Top = 2
        Width = 145
        Height = 21
        ComponentInspector = IDEInspector1
        TabOrder = 0
      end
    end
  end
  object IDEPaletteButtons1: TIDEPaletteButtons
    Left = 744
    Top = 0
    Width = 210
    Height = 708
    Align = alRight
    BevelKind = bkFlat
    BorderStyle = bsNone
    ButtonFlow = cbfVertical
    ButtonHeight = 29
    ButtonWidth = 29
    ButtonOptions = [boFullSize, boGradientFill, boShowCaptions, boBoldCaptions, boUsePlusMinus]
    Categories = <
      item
        Caption = 'Standard'
        Color = 16771818
        Collapsed = False
        Items = <
          item
            Caption = 'TMainMenu'
          end
          item
            Caption = 'TPopupMenu'
          end
          item
            Caption = 'TLabel'
          end
          item
            Caption = 'TEdit'
          end
          item
            Caption = 'TMemo'
          end
          item
            Caption = 'TButton'
          end
          item
            Caption = 'TCheckBox'
          end
          item
            Caption = 'TRadioButton'
          end
          item
            Caption = 'TListBox'
          end
          item
            Caption = 'TComboBox'
          end
          item
            Caption = 'TGroupBox'
          end
          item
            Caption = 'TPanel'
          end
          item
            Caption = 'TRadioGroup'
          end>
      end
      item
        Caption = 'Additional'
        Color = 16771839
        Collapsed = False
        Items = <
          item
            Caption = 'TBitBtn'
          end
          item
            Caption = 'TSpeedButton'
          end
          item
            Caption = 'TMaskEdit'
          end
          item
            Caption = 'TImage'
          end
          item
            Caption = 'TShape'
          end
          item
            Caption = 'TBevel'
          end
          item
            Caption = 'TStaticText'
          end
          item
            Caption = 'TSplitter'
          end>
      end
      item
        Caption = 'Win32'
        Color = 16053492
        Collapsed = False
        Items = <
          item
            Caption = 'TTabControl'
          end
          item
            Caption = 'TPageControl'
          end
          item
            Caption = 'TImageList'
          end
          item
            Caption = 'TProgressBar'
          end
          item
            Caption = 'TTreeView'
          end
          item
            Caption = 'TListView'
          end
          item
            Caption = 'TDateTimePicker'
          end>
      end
      item
        Caption = 'Dialogs'
        Color = 15395839
        Collapsed = False
        Items = <
          item
            Caption = 'TOpenDialog'
          end
          item
            Caption = 'TSaveDialog'
          end
          item
            Caption = 'TFontDialog'
          end
          item
            Caption = 'TColorDialog'
          end
          item
            Caption = 'TPrintDialog'
          end
          item
            Caption = 'TPrinterSetupDialog'
          end>
      end>
    RegularButtonColor = clWhite
    SelectedButtonColor = 15132390
    TabOrder = 2
    CategoryColor = clNone
    CategoryColorTo = clNone
    ExplicitHeight = 688
  end
  object IDEEngine1: TIDEEngine
    DesignControl = IDEFormDesignControl1
    Inspector = IDEInspector1
    ComponentCombo = IDEComponentComboBox1
    Scripter = IDEScripter1
    PaletteButtons = IDEPaletteButtons1
    Memo = IDEMemo1
    TabControl = TabControl1
    Options.AutoHideTabControl = True
    FileExtPascalUnit = '.psc'
    FileExtForm = '.sfm'
    FileExtBasicUnit = '.bsc'
    AutoStyler = True
    ProjectExt = '.ssproj'
    Left = 312
    Top = 232
  end
  object IDEScripter1: TIDEScripter
    DefaultLanguage = slPascal
    SaveCompiledCode = False
    ShortBooleanEval = True
    LibOptions.SearchPath.Strings = (
      '$(CURDIR)'
      '$(APPDIR)')
    LibOptions.UseScriptFiles = False
    CallExecHookEvent = False
    Left = 312
    Top = 288
  end
  object atScriptDebugger1: TatScriptDebugger
    Scripter = IDEScripter1
    UpdateSourceCode = True
    MemoReadOnly = False
    Left = 344
    Top = 168
  end
end

Steps to replicate

  1. Launch Program and click Edit Script - Notice how Form2 is named TForm2.
  2. Close Edit IDE.
  3. Click Run Script, close the Script, Run Script again.
  4. Click Edit Script - Notice how Form2 is now named TForm2_3.

If you click Run Script, it always appends an _X where X is the amount of times you ran the Script + 1.

This is the most stripped down version of the problem I could get. Our real application loads all these units and forms from a database. I can send the project your way if needed.

Thanks for your time

Thanks for the initial feedback. But yes, we need a compilable project that we could run at our side here, to properly debug it. Your code seems rather complex and using lots of specific code - including a custom IDE. Thus we need to reproduce it at our side, if you could send a minimal project without 3rd party components, that would be great, thank you in advance.

Got it. Project has been sent to help@tmssoftware.com. But in case an email gobbles up the attachment, I'll attach it here as well
FormsRenaming.zip (87.1 KB)

Thanks all!

Okay, after going and remove all references to the 3rd party component wwDBComboBox (including library units vcl.Wwdbedit, vcl.Wwdotdot, and vcl.Wwdbcomb) and and other 3rd party library units (adsdata, adsfunc, adstable, and adscnnct). Just to be able to compile the project.

I then had to go and add a TabSet to the FScriptIDE (with the code necessary to view the Forms code). Just so that I could see the source code for Unit2. Which was not possible with the project as is.

I compiled the project in 10.2, 10.3 Community, and 10.4. Then I followed the information provided to reproduce the issue with each build.

But, I did not experience the issue. I suspect that if the issue is there. That it might be because of the older compiler. I do have XE7 but I do not have it currently installed to test a build with it.

1 Like

Sorry about the bad units. Those are remnants from stripping this down to a core problem.

Attached is a gif of this project ran out of Delphi Seattle. I guess I'll get 10.4 up and running.

ScriptRenaming

Okay, after seeing your GIF. I can confirm that the issue is present. Even with 10.2, 10.3 Community, and 10.4. SInce you did not mention that where the issue was at. I had assumed that the issue was renaming the form2 in the source code. So that is where I was looking. And that is where the Devs were probably looking as well.

The problem is actually with the IDEComponentComboBox component. And yes, it does happen.

I didn't even think to suspect that combobox, but I guess that makes sense. Any hope for us? It's not game breaking, but I have script writers who do this pattern quite a few times in a session. And they often complain cause for them, everything must be perfect.

Well, all we can do is wait for the Devs to track down the problem in the IDEComponentComboBox and fix it. Then wait for them to release an update.

Okay, upon further review of the source code. I think I might have an idea as to what might be causing the issue.

In your Run Script button procedure you are creating a new instance of the IDEEngine and IDEScripter every time the button is Clicked. But, you do not free the instance of the IDEEngine and IDEScripter when the code leaves the Run Script button procedure. Yes, you created the IDEEngine and IDEScripter with the owner being the Application. So the application should free the instances of IDEEngine and IDEScripter. But the problem is, the application will only do that when the application closes.

So, every time you click on the Run Script button you end up with an instance of IDEEngine and IDEScripter still in memory.

And even though you are freeing each instance of the TFScriptIDE form created when the Edit Script button is click. I suspect that for some reason the IDEEngine and IDEScript instance for each TFScriptIDE form created is staying in memory.

That is why you are seeing the IDEComponentComboBox showing the _4 appended to the form name. It is seeing each instance of the script in each instance of IDEEngine and IDEScripter that was created and then not freed.

I would suggest that you work with a single instance of IDEEngine and IDEScripter. If you are using a two form project like your test probject. Than I would have the instances of the IDEScripter and IDEScripter on the main form. And then set the additional Scripter IDE components that are on the seperate form to use that instance only.

You can look at the ScripterProIDE Demo project's Main.pas (under Demos) and the IDEDialog.pas & fIDEEditor.pas source code (under Source > IDE) to see how it can be done.

1 Like

I think we can use your post and try to find a solution. Thank you very much for your time!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.