Ver código fonte

Put the preprocessor memo under the last tab (but keep it as FMemos[1]). Also add a separate CompScintEdit class so it's not possible to do stuff to it that should only apply to real files, such as saving and debugging.

Martijn Laan 5 anos atrás
pai
commit
2a5bf5879a
2 arquivos alterados com 190 adições e 149 exclusões
  1. 162 130
      Projects/CompForm.pas
  2. 28 19
      Projects/CompScintEdit.pas

+ 162 - 130
Projects/CompForm.pas

@@ -52,7 +52,7 @@ type
     CompilerFileIndex: Integer;
     LastWriteTime: TFileTime;
     HasLastWriteTime: Boolean;
-    Memo: TCompScintEdit;
+    Memo: TCompScintFileEdit;
   end;
 
   TIncludedFiles = TObjectList<TIncludedFile>;
@@ -183,7 +183,7 @@ type
     TInsertMsgBox: TMenuItem;
     ToolBarPanel: TPanel;
     HMailingList: TMenuItem;
-    MemosTabSet: TNewTabSet;
+    MemosTabSet: TNewTabSet; { First tab is the main memo, last tab is the preprocessor memo }
     FSaveAll: TMenuItem;
     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     procedure FExitClick(Sender: TObject);
@@ -274,9 +274,12 @@ type
     procedure FSaveAllClick(Sender: TObject);
   private
     { Private declarations }
-    FMemos: TList<TCompScintEdit>;                      { FMemos[0] is the main memo and FMemos[1] the preprocessor memo }
-    FMainMemo, FPreprocessorMemo: TCOmpScintEdit;       { These don't change }
-    FActiveMemo, FErrorMemo, FStepMemo: TCompScintEdit; { These change depending on user input }
+    FMemos: TList<TCompScintEdit>;                      { FMemos[0] is the main memo and FMemos[1] the preprocessor memo - also see MemosTabSet comment above }
+    FMainMemo: TCompScintFileEdit;                      { Doesn't change }
+    FPreprocessorMemo: TCompScintEdit;                  { Doesn't change }
+    FFileMemos: TList<TCompScintFileEdit>;              { All memos except FPreprocessorMemo }
+    FActiveMemo: TCompScintEdit;                        { These change depending on user input }
+    FErrorMemo, FStepMemo: TCompScintFileEdit;          { These change depending on user input }
     FMemosStyler: TInnoSetupStyler;                     { Single styler for all memos }
     FCompilerVersion: PCompilerVersionInfo;
     FMRUMainFilesMenuItems: array[0..MRUListMaxCount-1] of TMenuItem;
@@ -368,7 +371,8 @@ type
     procedure Go(AStepMode: TStepMode);
     procedure HideError;
     procedure InitializeFindText(Dlg: TFindDialog);
-    function InitializeMainMemo(const Memo: TCompScintEdit; const PopupMenu: TPopupMenu): TCompScintEdit;
+    function InitializeFileMemo(const Memo: TCompScintFileEdit; const PopupMenu: TPopupMenu): TCompScintFileEdit;
+    function InitializeMainMemo(const Memo: TCompScintFileEdit; const PopupMenu: TPopupMenu): TCompScintFileEdit;
     function InitializeMemo(const Memo: TCompScintEdit; const PopupMenu: TPopupMenu): TCompScintEdit;
     function InitializePreprocessedMemo(const Memo: TCompScintEdit; const PopupMenu: TPopupMenu): TCompScintEdit;
     procedure InitiateAutoComplete(const Key: AnsiChar);
@@ -380,8 +384,8 @@ type
     procedure MemoHintShow(Sender: TObject; var Info: TScintHintInfo);
     procedure MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure MemoKeyPress(Sender: TObject; var Key: Char);
-    procedure MemoLinesDeleted(Memo: TCompScintEdit; FirstLine, Count, FirstAffectedLine: Integer);
-    procedure MemoLinesInserted(Memo: TCompScintEdit; FirstLine, Count: integer);
+    procedure MemoLinesDeleted(Memo: TCompScintFileEdit; FirstLine, Count, FirstAffectedLine: Integer);
+    procedure MemoLinesInserted(Memo: TCompScintFileEdit; FirstLine, Count: integer);
     procedure MemoMarginClick(Sender: TObject; MarginNumber: Integer;
       Line: Integer);
     procedure MemoModifiedChange(Sender: TObject);
@@ -391,18 +395,18 @@ type
     procedure MoveCaretAndActivateMemo(const AMemo: TCompScintEdit; const LineNumber: Integer; const AlwaysResetColumn: Boolean);
     procedure NewMainFile;
     procedure NewMainFileUsingWizard;
-    procedure OpenFile(AMemo: TCompScintEdit; AFilename: String; const MainMemoAddToRecentDocs: Boolean);
+    procedure OpenFile(AMemo: TCompScintFileEdit; AFilename: String; const MainMemoAddToRecentDocs: Boolean);
     procedure OpenMRUMainFile(const AFilename: String);
     procedure ParseDebugInfo(DebugInfo: Pointer);
     procedure ReadMRUMainFilesList;
     procedure ReadMRUParametersList;
     procedure ResetAllMemosLineState;
     procedure StartProcess;
-    function SaveFile(const AMemo: TCompScintEdit; const SaveAs: Boolean): Boolean;
+    function SaveFile(const AMemo: TCompScintFileEdit; const SaveAs: Boolean): Boolean;
     procedure SaveKnownIncludedFiles(const AFilename: String);
-    procedure SetErrorLine(const AMemo: TCompScintEdit; const ALine: Integer);
+    procedure SetErrorLine(const AMemo: TCompScintFileEdit; const ALine: Integer);
     procedure SetStatusPanelVisible(const AVisible: Boolean);
-    procedure SetStepLine(const AMemo: TCompScintEdit; ALine: Integer);
+    procedure SetStepLine(const AMemo: TCompScintFileEdit; ALine: Integer);
     procedure ShowOpenMainFileDialog(const Examples: Boolean);
     procedure StatusMessage(const Kind: TStatusMessageKind; const S: String);
     procedure SyncEditorOptions;
@@ -417,7 +421,7 @@ type
       const ASecondsRemaining: Integer; const ABytesCompressedPerSecond: Cardinal);
     procedure UpdateEditModePanel;
     procedure UpdateIncludedFilesMemos;
-    procedure UpdateLineMarkers(const AMemo: TCompScintEdit; const Line: Integer);
+    procedure UpdateLineMarkers(const AMemo: TCompScintFileEdit; const Line: Integer);
     procedure UpdateMemosTabSetVisibility;
     procedure UpdateModifiedPanel;
     procedure UpdateNewMainFileButtons;
@@ -431,7 +435,7 @@ type
     procedure WMDebuggerHello(var Message: TMessage); message WM_Debugger_Hello;
     procedure WMDebuggerGoodbye(var Message: TMessage); message WM_Debugger_Goodbye;
     procedure WMDebuggerQueryVersion(var Message: TMessage); message WM_Debugger_QueryVersion;
-    procedure GetMemoAndLineNumberFromEntry(Kind, Index: Integer; var Memo: TCompScintEdit; var LineNumber: Integer);
+    procedure GetMemoAndLineNumberFromEntry(Kind, Index: Integer; var Memo: TCompScintFileEdit; var LineNumber: Integer);
     procedure DebuggerStepped(var Message: TMessage; const Intermediate: Boolean);
     procedure WMDebuggerStepped(var Message: TMessage); message WM_Debugger_Stepped;
     procedure WMDebuggerSteppedIntermediate(var Message: TMessage); message WM_Debugger_SteppedIntermediate;
@@ -476,7 +480,7 @@ uses
 const
   { Memos }
   MaxMemos = 12; { Includes the main and preprocessor memo's }
-  FirstIncludedFilesMemoIndex = 2;
+  FirstIncludedFilesMemoIndex = 1; { This is an index into FFileMemos }
 
   { Status bar panel indexes }
   spCaretPos = 0;
@@ -518,12 +522,9 @@ begin
   Memo.AutoCompleteFontName := Font.Name;
   Memo.AutoCompleteFontSize := Font.Size;
   Memo.CodePage := CP_UTF8;
-  Memo.CompilerFileIndex := UnknownCompilerFileIndex;
-  Memo.ErrorLine := -1;
   Memo.Font.Name := 'Courier New';
   Memo.Font.Size := 10;
   Memo.ShowHint := True;
-  Memo.StepLine := -1;
   Memo.Styler := FMemosStyler;
   Memo.PopupMenu := PopupMenu;
   Memo.OnChange := MemoChange;
@@ -540,9 +541,18 @@ begin
   Result := Memo;
 end;
 
-function TCompileForm.InitializeMainMemo(const Memo: TCompScintEdit; const PopupMenu: TPopupMenu): TCompScintEdit;
+function TCompileForm.InitializeFileMemo(const Memo: TCompScintFileEdit; const PopupMenu: TPopupMenu): TCompScintFileEdit;
 begin
   InitializeMemo(Memo, PopupMenu);
+  Memo.CompilerFileIndex := UnknownCompilerFileIndex;
+  Memo.ErrorLine := -1;
+  Memo.StepLine := -1;
+  Result := Memo;
+end;
+
+function TCompileForm.InitializeMainMemo(const Memo: TCompScintFileEdit; const PopupMenu: TPopupMenu): TCompScintFileEdit;
+begin
+  InitializeFileMemo(Memo, PopupMenu);
   Memo.AcceptDroppedFiles := True;
   Memo.CompilerFileIndex := -1;
   Memo.OnDropFiles := MainMemoDropFiles;
@@ -644,6 +654,7 @@ var
   I: Integer;
   NewItem: TMenuItem;
   PopupMenu: TPopupMenu;
+  Memo: TCompScintEdit;
 begin
   inherited;
 
@@ -692,12 +703,16 @@ begin
   FMemosStyler.IsppInstalled := IsppInstalled;
   FTheme := TTheme.Create;
   FMemos := TList<TCompScintEdit>.Create;
-  FMainMemo := InitializeMainMemo(TCompScintEdit.Create(Self), PopupMenu);
+  FMainMemo := InitializeMainMemo(TCompScintFileEdit.Create(Self), PopupMenu);
   FMemos.Add(FMainMemo);
   FPreprocessorMemo := InitializePreprocessedMemo(TCompScintEdit.Create(Self), PopupMenu);
   FMemos.Add(FPreprocessorMemo);
   for I := FMemos.Count to MaxMemos-1 do
-    FMemos.Add(InitializeMemo(TCompScintEdit.Create(Self), PopupMenu));
+    FMemos.Add(InitializeFileMemo(TCompScintFileEdit.Create(Self), PopupMenu));
+  FFileMemos := TList<TCompScintFileEdit>.Create;
+  for Memo in FMemos do
+    if Memo is TCompScintFileEdit then
+      FFileMemos.Add(TCompScintFileEdit(Memo));
   FActiveMemo := FMainMemo;
   FActiveMemo.Visible := True;
   FErrorMemo := FMainMemo;
@@ -796,6 +811,7 @@ begin
   FSignTools.Free;
   FMRUParametersList.Free;
   FMRUMainFilesList.Free;
+  FFileMemos.Free;
   FMemos.Free;
 
   inherited;
@@ -929,7 +945,7 @@ end;
 
 procedure TCompileForm.NewMainFile;
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
 begin
   HideError;
   FUninstExe := '';
@@ -937,7 +953,7 @@ begin
     FDebugTarget := dtSetup;
     UpdateTargetMenu;
   end;
-  for Memo in FMemos do
+  for Memo in FFileMemos do
     if Memo.Used then
       Memo.BreakPoints.Clear;
   DestroyDebugInfo;
@@ -1050,7 +1066,7 @@ begin
   end;
 end;
 
-procedure TCompileForm.OpenFile(AMemo: TCompScintEdit; AFilename: String;
+procedure TCompileForm.OpenFile(AMemo: TCompScintFileEdit; AFilename: String;
   const MainMemoAddToRecentDocs: Boolean);
 
   function IsStreamUTF8Encoded(const Stream: TStream): Boolean;
@@ -1106,7 +1122,7 @@ begin
   end;
 end;
 
-function TCompileForm.SaveFile(const AMemo: TCompScintEdit; const SaveAs: Boolean): Boolean;
+function TCompileForm.SaveFile(const AMemo: TCompScintFileEdit; const SaveAs: Boolean): Boolean;
 
   procedure SaveMemoTo(const FN: String);
   var
@@ -1176,7 +1192,7 @@ end;
 
 function TCompileForm.ConfirmCloseFile(const PromptToSave: Boolean): Boolean;
 
-  function PromptToSaveMemo(const AMemo: TCompScintEdit): Boolean;
+  function PromptToSaveMemo(const AMemo: TCompScintFileEdit): Boolean;
   var
     FileTitle: String;
   begin
@@ -1195,7 +1211,7 @@ function TCompileForm.ConfirmCloseFile(const PromptToSave: Boolean): Boolean;
   end;
 
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
 begin
   if FCompiling then begin
     MsgBox('Please stop the compile process before performing this command.',
@@ -1209,7 +1225,7 @@ begin
   end;
   Result := True;
   if PromptToSave then begin
-    for Memo in FMemos do begin
+    for Memo in FFileMemos do begin
       if Memo.Used then begin
         Result := PromptToSaveMemo(Memo);
         if not Result then
@@ -1412,15 +1428,15 @@ end;
 
 procedure TCompileForm.CompileFile(AFilename: String; const ReadFromFile: Boolean);
 
-  function GetMemoFromErrorFilename(const ErrorFilename: String): TCompScintEdit;
+  function GetMemoFromErrorFilename(const ErrorFilename: String): TCompScintFileEdit;
   var
-    Memo: TCompScintEdit;
+    Memo: TCompScintFileEdit;
   begin
     if ErrorFilename = '' then
       Result := FMainMemo
     else begin
       if FOptions.OpenIncludedFiles then begin
-        for Memo in FMemos do begin
+        for Memo in FFileMemos do begin
           if Memo.Used and (PathCompare(Memo.Filename, ErrorFilename) = 0) then begin
             Result := Memo;
             Exit;
@@ -1437,7 +1453,8 @@ var
   AppData: TAppData;
   StartTime, ElapsedTime, ElapsedSeconds: DWORD;
   I: Integer;
-  Memo, OldActiveMemo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
+  OldActiveMemo: TCompScintEdit;
 begin
   if FCompiling then begin
     { Shouldn't get here, but just in case... }
@@ -1448,7 +1465,7 @@ begin
   if not ReadFromFile then begin
     if FOptions.OpenIncludedFiles then begin
       { Included files must always be saved since they're not read from the editor by the compiler }
-      for Memo in FMemos do begin
+      for Memo in FFileMemos do begin
         if (Memo <> FMainMemo) and Memo.Used and Memo.Modified then begin
           if FOptions.Autosave then begin
             if not SaveFile(Memo, False) then
@@ -1499,9 +1516,8 @@ begin
     FActiveMemo.Cursor := crAppStart;
     FActiveMemo.SetCursorID(999);  { hack to keep it from overriding Cursor }
     CompilerOutputList.Cursor := crAppStart;
-    for Memo in FMemos do
-      if Memo <> FPreprocessorMemo then
-        Memo.ReadOnly := True;
+    for Memo in FFileMemos do
+      Memo.ReadOnly := True;
     UpdateEditModePanel;
     HideError;
     CompilerOutputList.Clear;
@@ -1587,9 +1603,8 @@ begin
     OldActiveMemo.Cursor := crDefault;
     OldActiveMemo.SetCursorID(SC_CURSORNORMAL);
     CompilerOutputList.Cursor := crDefault;
-    for Memo in FMemos do
-      if Memo <> FPreprocessorMemo then
-        Memo.ReadOnly := False;
+    for Memo in FFileMemos do
+      Memo.ReadOnly := False;
     UpdateEditModePanel;
     UpdateRunMenu;
     UpdateCaption;
@@ -1667,11 +1682,11 @@ procedure TCompileForm.FMenuClick(Sender: TObject);
 var
   I: Integer;
 begin
-  FSave.Enabled := FActiveMemo <> FPreprocessorMemo;
+  FSave.Enabled := FActiveMemo is TCompScintFileEdit;
   FSaveMainFileAs.Enabled := FActiveMemo = FMainMemo;
   FSaveEncoding.Enabled := FSave.Enabled;
-  FSaveEncodingAuto.Checked := not FActiveMemo.SaveInUTF8Encoding;
-  FSaveEncodingUTF8.Checked := FActiveMemo.SaveInUTF8Encoding;
+  FSaveEncodingAuto.Checked := FSave.Enabled and not TCompScintFileEdit(FActiveMemo).SaveInUTF8Encoding;
+  FSaveEncodingUTF8.Checked := FSave.Enabled and TCompScintFileEdit(FActiveMemo).SaveInUTF8Encoding;
   FSaveAll.Visible := FOptions.OpenIncludedFiles;
   ReadMRUMainFilesList;
   FMRUMainFilesSep.Visible := FMRUMainFilesList.Count <> 0;
@@ -1722,19 +1737,19 @@ end;
 
 procedure TCompileForm.FSaveClick(Sender: TObject);
 begin
-  SaveFile(FActiveMemo, Sender = FSaveMainFileAs);
+  SaveFile(TCompScintFileEdit(FActiveMemo), Sender = FSaveMainFileAs);
 end;
 
 procedure TCompileForm.FSaveEncodingItemClick(Sender: TObject);
 begin
-  FActiveMemo.SaveInUTF8Encoding := (Sender = FSaveEncodingUTF8);
+  TCompScintFileEdit(FActiveMemo).SaveInUTF8Encoding := (Sender = FSaveEncodingUTF8);
 end;
 
 procedure TCompileForm.FSaveAllClick(Sender: TObject);
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
 begin
-  for Memo in FMemos do
+  for Memo in FFileMemos do
     if Memo.Used and Memo.Modified then
       SaveFile(Memo, False);
 end;
@@ -2168,14 +2183,26 @@ begin
 end;
 
 procedure TCompileForm.MemosTabSetClick(Sender: TObject);
+
+  function TabIndexToMemoIndex(const TabIndex, MaxTabIndex: Integer): Integer;
+  begin
+    if TabIndex = 0 then
+      Result := 0 { First tab displays the main memo which is FMemos[0] }
+    else if TabIndex = MaxTabIndex then
+      Result := 1 { Last tab displays the preprocessor memo which is FMemos[1] }
+    else
+      Result := TabIndex+1; { Other tabs display include files which start second tab but at FMemos[2] }
+  end;
 var
   Memo: TCompScintEdit;
-  I: Integer;
+  TabIndex, MaxTabIndex: Integer;
 begin
   FActiveMemo.CancelAutoComplete;
-  for I := 0 to MemosTabSet.Tabs.Count-1 do begin
-    Memo := FMemos[I];
-    Memo.Visible := (I = MemosTabSet.TabIndex);
+
+  MaxTabIndex := MemosTabSet.Tabs.Count-1;
+  for TabIndex := 0 to MaxTabIndex do begin
+    Memo := FMemos[TabIndexToMemoIndex(TabIndex, MaxTabIndex)];
+    Memo.Visible := (TabIndex = MemosTabSet.TabIndex);
     if Memo.Visible then begin
       FActiveMemo := Memo;
       ActiveControl := Memo;
@@ -2509,7 +2536,7 @@ begin
   MemosTabSet.TabIndex := FMemos.IndexOf(AMemo);
 end;
 
-procedure TCompileForm.SetErrorLine(const AMemo: TCompScintEdit; const ALine: Integer);
+procedure TCompileForm.SetErrorLine(const AMemo: TCompScintFileEdit; const ALine: Integer);
 var
   OldLine: Integer;
 begin
@@ -2530,7 +2557,7 @@ begin
   end;
 end;
 
-procedure TCompileForm.SetStepLine(const AMemo: TCompScintEdit; ALine: Integer);
+procedure TCompileForm.SetStepLine(const AMemo: TCompScintFileEdit; ALine: Integer);
 var
   OldLine: Integer;
 begin
@@ -2574,7 +2601,7 @@ end;
 
 procedure TCompileForm.UpdateMemosTabSetVisibility;
 begin
-  MemosTabSet.Visible := FMemos[FirstIncludedFilesMemoIndex].Used;
+  MemosTabSet.Visible := FPreprocessorMemo.Used or FFileMemos[FirstIncludedFilesMemoIndex].Used;
   if not MemosTabSet.Visible then
     MemosTabSet.TabIndex := 0; { For next time }
 end;
@@ -2594,21 +2621,21 @@ var
   I, NextMemoIndex: Integer;
   SaveTabName: String;
 begin
-  if FOptions.OpenIncludedFiles and (FIncludedFiles.Count > 0) then begin
-    NewTabs := nil;
-    NewHints := nil;
-    try
-      NewTabs := TStringList.Create;
-      NewTabs.Add(MemosTabSet.Tabs[0]); { 'Main Script' }
-      NewTabs.Add(MemosTabSet.Tabs[1]); { 'Preprocessor Output' }
-      NewHints := TStringList.Create;
-      NewHints.Add(GetFileTitle(FMainMemo.Filename));
-      NewHints.Add('');
+  NewTabs := nil;
+  NewHints := nil;
+  try
+    NewTabs := TStringList.Create;
+    NewTabs.Add(MemosTabSet.Tabs[0]); { 'Main Script' }
+    NewTabs.Add('Preprocessor Output');
+    NewHints := TStringList.Create;
+    NewHints.Add(GetFileTitle(FMainMemo.Filename));
+    NewHints.Add('');
+    if FOptions.OpenIncludedFiles and (FIncludedFiles.Count > 0) then begin
       NextMemoIndex := FirstIncludedFilesMemoIndex;
       FLoadingIncludedFiles := True;
       try
         for IncludedFile in FIncludedFiles do begin
-          IncludedFile.Memo := FMemos[NextMemoIndex];
+          IncludedFile.Memo := FFileMemos[NextMemoIndex];
           try
             if not IncludedFile.Memo.Used or
               ((PathCompare(IncludedFile.Memo.Filename, IncludedFile.Filename) <> 0) or
@@ -2623,8 +2650,8 @@ begin
              { Previously the included file came from the history }
               IncludedFile.Memo.CompilerFileIndex := IncludedFile.CompilerFileIndex;
             end;
-            NewTabs.Add(PathExtractName(IncludedFile.Filename));
-            NewHints.Add(GetFileTitle(IncludedFile.Filename));
+            NewTabs.Insert(1, PathExtractName(IncludedFile.Filename));
+            NewHints.Insert(1, GetFileTitle(IncludedFile.Filename));
 
             Inc(NextMemoIndex);
             if NextMemoIndex = FMemos.Count then
@@ -2640,30 +2667,30 @@ begin
         FLoadingIncludedFiles := False;
       end;
       { Hide any remaining memos }
-      for I := NextMemoIndex to FMemos.Count-1 do begin
-        FMemos[I].BreakPoints.Clear;
-        FMemos[I].Used := False;
-        FMemos[I].Visible := False;
+      for I := NextMemoIndex to FFileMemos.Count-1 do begin
+        FFileMemos[I].BreakPoints.Clear;
+        FFileMemos[I].Used := False;
+        FFileMemos[I].Visible := False;
       end;
-      { Set new tabs, try keep same file open }
-      SaveTabName := MemosTabSet.Tabs[MemosTabSet.TabIndex];
-      MemosTabSet.Tabs := NewTabs;
-      MemosTabSet.Hints := NewHints;
-      I := MemosTabSet.Tabs.IndexOf(SaveTabName);
-      if I <> -1 then
-         MemosTabSet.TabIndex := I;
-    finally
-      NewHints.Free;
-      NewTabs.Free;
-    end;
-  end else begin
-    for I := FirstIncludedFilesMemoIndex to FMemos.Count-1 do begin
-      FMemos[I].BreakPoints.Clear;
-      FMemos[I].Used := False;
-      FMemos[I].Visible := False;
+    end else begin
+      for I := FirstIncludedFilesMemoIndex to FFileMemos.Count-1 do begin
+        FFileMemos[I].BreakPoints.Clear;
+        FFileMemos[I].Used := False;
+        FFileMemos[I].Visible := False;
+      end;
+      for IncludedFile in FIncludedFiles do
+        IncludedFile.Memo := nil;
     end;
-    for IncludedFile in FIncludedFiles do
-      IncludedFile.Memo := nil;
+    { Set new tabs, try keep same file open }
+    SaveTabName := MemosTabSet.Tabs[MemosTabSet.TabIndex];
+    MemosTabSet.Tabs := NewTabs;
+    MemosTabSet.Hints := NewHints;
+    I := MemosTabSet.Tabs.IndexOf(SaveTabName);
+    if I <> -1 then
+       MemosTabSet.TabIndex := I;
+  finally
+    NewHints.Free;
+    NewTabs.Free;
   end;
 
   UpdateMemosTabSetVisibility;
@@ -2749,7 +2776,7 @@ end;
 
 procedure TCompileForm.MemoChange(Sender: TObject; const Info: TScintEditChangeInfo);
 
-  procedure MemoLinesInsertedOrDeleted(Memo: TCompScintEdit);
+  procedure MemoLinesInsertedOrDeleted(Memo: TCompScintFileEdit);
   var
     FirstAffectedLine, Line, LinePos: Integer;
   begin
@@ -2769,13 +2796,13 @@ procedure TCompileForm.MemoChange(Sender: TObject; const Info: TScintEditChangeI
   end;
 
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
 begin
-  Memo := Sender as TCompScintEdit;
-
-  if (Memo <> FMainMemo) and FLoadingIncludedFiles then
+  if not (Sender is TCompScintFileEdit) or ((Sender <> FMainMemo) and FLoadingIncludedFiles) then
     Exit;
 
+  Memo := TCompScintFileEdit(Sender);
+
   FModifiedAnySinceLastCompile := True;
   if FDebugging then
     FModifiedAnySinceLastCompileAndGo := True
@@ -2790,7 +2817,7 @@ begin
   if Memo = FErrorMemo then begin
     { When the Delete key is pressed, the caret doesn't move, so reset
       FErrorCaretPosition to ensure that OnUpdateUI calls HideError }
-    Memo.ErrorCaretPosition := -1;
+    FErrorMemo.ErrorCaretPosition := -1;
   end;
 
   { The change should trigger restyling. Allow the styler to see the current
@@ -3038,14 +3065,15 @@ begin
   Line := FActiveMemo.GetLineFromPosition(Pos);
 
   { Check if cursor is over a [Code] variable }
-  if FMemosStyler.GetSectionFromLineState(FActiveMemo.Lines.State[Line]) = scCode then begin
+  if (FActiveMemo is TCompScintFileEdit) and
+     (FMemosStyler.GetSectionFromLineState(FActiveMemo.Lines.State[Line]) = scCode) then begin
     { Note: The '+ 1' is needed so that when the mouse is over a '.'
       between two words, it won't match the word to the left of the '.' }
     I := FActiveMemo.GetWordStartPosition(Pos + 1, True);
     J := FActiveMemo.GetWordEndPosition(Pos, True);
     if J > I then begin
-      DebugEntry := GetCodeVariableDebugEntryFromFileLineCol(FActiveMemo.CompilerFileIndex, Line,
-        GetCodeColumnFromPosition(I));
+      DebugEntry := GetCodeVariableDebugEntryFromFileLineCol(TCompScintFileEdit(FActiveMemo).CompilerFileIndex,
+        Line, GetCodeColumnFromPosition(I));
       if DebugEntry <> nil then begin
         case EvaluateVariableEntry(DebugEntry, Output) of
           1: Info.HintStr := Output;
@@ -3131,15 +3159,15 @@ begin
   DebuggingStopped(True);
 end;
 
-procedure TCompileForm.GetMemoAndLineNumberFromEntry(Kind, Index: Integer; var Memo: TCompScintEdit; var LineNumber: Integer);
+procedure TCompileForm.GetMemoAndLineNumberFromEntry(Kind, Index: Integer; var Memo: TCompScintFileEdit; var LineNumber: Integer);
 
-  function GetMemoFromDebugEntryFileIndex(const FileIndex: Integer): TCompScintEdit;
+  function GetMemoFromDebugEntryFileIndex(const FileIndex: Integer): TCompScintFileEdit;
   var
-    Memo: TCompScintEdit;
+    Memo: TCompScintFileEdit;
   begin
     Result := nil;
     if FOptions.OpenIncludedFiles then begin
-      for Memo in FMemos do begin
+      for Memo in FFileMemos do begin
         if Memo.Used and (Memo.CompilerFileIndex = FileIndex) then begin
           Result := Memo;
           Exit;
@@ -3186,7 +3214,7 @@ end;
 
 procedure TCompileForm.DebuggerStepped(var Message: TMessage; const Intermediate: Boolean);
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   LineNumber: Integer;
 begin
   GetMemoAndLineNumberFromEntry(Message.WParam, Message.LParam, Memo, LineNumber);
@@ -3229,7 +3257,7 @@ end;
 
 procedure TCompileForm.WMDebuggerException(var Message: TMessage);
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   LineNumber: Integer;
   S: String;
 begin
@@ -3320,10 +3348,10 @@ end;
 procedure TCompileForm.DestroyDebugInfo;
 var
   HadDebugInfo: Boolean;
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
 begin
   HadDebugInfo := False;
-  for Memo in FMemos do begin
+  for Memo in FFileMemos do begin
     if Assigned(Memo.LineState) then begin
       Memo.LineStateCapacity := 0;
       Memo.LineStateCount := 0;
@@ -3351,17 +3379,17 @@ end;
 
 var
   PrevCompilerFileIndex: Integer;
-  PrevMemo: TCompScintEdit;
+  PrevMemo: TCompScintFileEdit;
 
 procedure TCompileForm.ParseDebugInfo(DebugInfo: Pointer);
 
-  function GetMemoFromCompilerFileIndex(const CompilerFileIndex: Integer): TCompScintEdit;
+  function GetMemoFromCompilerFileIndex(const CompilerFileIndex: Integer): TCompScintFileEdit;
   var
-    Memo: TCompScintEdit;
+    Memo: TCompScintFileEdit;
   begin
     if (PrevCompilerFileIndex <> CompilerFileIndex) then begin
       PrevMemo := nil;
-      for Memo in FMemos do begin
+      for Memo in FFileMemos do begin
         if Memo.Used and (Memo.CompilerFileIndex = CompilerFileIndex) then begin
           PrevMemo := Memo;
           Break;
@@ -3375,7 +3403,7 @@ procedure TCompileForm.ParseDebugInfo(DebugInfo: Pointer);
 { This creates and fills the DebugEntries and Memo LineState arrays }
 var
   Header: PDebugInfoHeader;
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   Size: Cardinal;
   I: Integer;
 begin
@@ -3387,7 +3415,7 @@ begin
     raise Exception.Create('Unrecognized debug info format');
 
   try
-    for Memo in FMemos do begin
+    for Memo in FFileMemos do begin
       if Memo.Used then begin
         I := Memo.Lines.Count;
         Memo.LineState := AllocMem(SizeOf(TLineState) * (I + LineStateGrowAmount));
@@ -3438,10 +3466,10 @@ end;
 procedure TCompileForm.ResetAllMemosLineState;
 { Changes green dots back to grey dots }
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   I: Integer;
 begin
-  for Memo in FMemos do begin
+  for Memo in FFileMemos do begin
     if Memo.Used and Assigned(Memo.LineState) then begin
       for I := 0 to Memo.LineStateCount-1 do begin
         if Memo.LineState[I] = lnEntryProcessed then begin
@@ -3856,12 +3884,14 @@ procedure TCompileForm.RRunToCursorClick(Sender: TObject);
     I: Integer;
   begin
     Result := False;
-    for I := 0 to FDebugEntriesCount-1 do begin
-      if (FDebugEntries[I].FileIndex = Memo.CompilerFileIndex) and
-         (FDebugEntries[I].LineNumber = LineNumber) then begin
-        DebugEntry := FDebugEntries[I];
-        Result := True;
-        Break;
+    if Memo is TCompScintFileEdit then begin
+      for I := 0 to FDebugEntriesCount-1 do begin
+        if (FDebugEntries[I].FileIndex = TCompScintFileEdit(Memo).CompilerFileIndex) and
+           (FDebugEntries[I].LineNumber = LineNumber) then begin
+          DebugEntry := FDebugEntries[I];
+          Result := True;
+          Break;
+        end;
       end;
     end;
   end;
@@ -4134,11 +4164,11 @@ const
       'also been made in the source editor.' + SNewLine2 + 'Do you want to ' +
       'reload the file and lose the changes made in the source editor?');
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   NewTime: TFileTime;
   Changed: Boolean;
 begin
-  for Memo in FMemos do begin
+  for Memo in FFileMemos do begin
     if (Memo.Filename = '') or not Memo.Used then
       Continue;
 
@@ -4261,14 +4291,16 @@ end;
 
 procedure TCompileForm.ToggleBreakPoint(Line: Integer);
 var
+  Memo: TCompScintFileEdit;
   I: Integer;
 begin
-  I := FActiveMemo.BreakPoints.IndexOf(Line);
+  Memo := TCompScintFileEdit(FActiveMemo);
+  I := Memo.BreakPoints.IndexOf(Line);
   if I = -1 then
-    FActiveMemo.BreakPoints.Add(Line)
+    Memo.BreakPoints.Add(Line)
   else
-    FActiveMemo.BreakPoints.Delete(I);
-  UpdateLineMarkers(FActiveMemo, Line);
+    Memo.BreakPoints.Delete(I);
+  UpdateLineMarkers(Memo, Line);
 end;
 
 procedure TCompileForm.MemoMarginClick(Sender: TObject; MarginNumber: Integer;
@@ -4283,7 +4315,7 @@ begin
   ToggleBreakPoint(FActiveMemo.CaretLine);
 end;
 
-procedure TCompileForm.MemoLinesInserted(Memo: TCompScintEdit; FirstLine, Count: integer);
+procedure TCompileForm.MemoLinesInserted(Memo: TCompScintFileEdit; FirstLine, Count: integer);
 var
   I, Line: Integer;
 begin
@@ -4321,7 +4353,7 @@ begin
   end;
 end;
 
-procedure TCompileForm.MemoLinesDeleted(Memo: TCompScintEdit; FirstLine, Count,
+procedure TCompileForm.MemoLinesDeleted(Memo: TCompScintFileEdit; FirstLine, Count,
   FirstAffectedLine: Integer);
 var
   I, Line: Integer;
@@ -4387,7 +4419,7 @@ begin
   UpdateLineMarkers(Memo, FirstAffectedLine);
 end;
 
-procedure TCompileForm.UpdateLineMarkers(const AMemo: TCompScintEdit; const Line: Integer);
+procedure TCompileForm.UpdateLineMarkers(const AMemo: TCompScintFileEdit; const Line: Integer);
 var
   NewMarker: Integer;
 begin
@@ -4431,10 +4463,10 @@ end;
 
 procedure TCompileForm.UpdateAllMemosLineMarkers;
 var
-  Memo: TCompScintEdit;
+  Memo: TCompScintFileEdit;
   Line: Integer;
 begin
-  for Memo in FMemos do
+  for Memo in FFileMemos do
     if Memo.Used then
       for Line := 0 to Memo.Lines.Count-1 do
         UpdateLineMarkers(Memo, Line);

+ 28 - 19
Projects/CompScintEdit.pas

@@ -39,16 +39,24 @@ type
   TLineStateArray = array[0..0] of TLineState;
 
   TCompScintEdit = class(TScintEdit)
+  private
+    FTheme: TTheme;
+    FUsed: Boolean;
+  protected
+    procedure CreateWnd; override;
+  public
+    property Theme: TTheme read FTheme write FTheme;
+    property Used: Boolean read FUsed write FUsed;
+    procedure UpdateThemeColors;
+  end;
+
+  TCompScintFileEdit = class(TCompScintEdit)
   private
     FBreakPoints: TList<Integer>;
     FCompilerFileIndex: Integer;
     FFilename: String;
     FFileLastWriteTime: TFileTime;
     FSaveInUTF8Encoding: Boolean;
-    FTheme: TTheme;
-    FUsed: Boolean;
-  protected
-    procedure CreateWnd; override;
   public
     ErrorLine, ErrorCaretPosition: Integer;
     StepLine: Integer;
@@ -61,27 +69,14 @@ type
     property CompilerFileIndex: Integer read FCompilerFileIndex write FCompilerFileIndex;
     property FileLastWriteTime: TFileTime read FFileLastWriteTime write FFileLastWriteTime;
     property SaveInUTF8Encoding: Boolean read FSaveInUTF8Encoding write FSaveInUTF8Encoding;
-    property Theme: TTheme read FTheme write FTheme;
-    property Used: Boolean read FUsed write FUsed;
-    procedure UpdateThemeColors;
   end;
 
 implementation
 
 uses
   ScintInt;
-
-constructor TCompScintEdit.Create;
-begin
-  inherited;
-  FBreakPoints := TList<Integer>.Create;
-end;
-
-destructor TCompScintEdit.Destroy;
-begin
-  FBreakPoints.Free;
-  inherited;
-end;
+  
+{ TCompScintEdit }
 
 procedure TCompScintEdit.CreateWnd;
 const
@@ -210,4 +205,18 @@ begin
   end;
 end;
 
+{ TCompScintFileEdit }
+
+constructor TCompScintFileEdit.Create;
+begin
+  inherited;
+  FBreakPoints := TList<Integer>.Create;
+end;
+
+destructor TCompScintFileEdit.Destroy;
+begin
+  FBreakPoints.Free;
+  inherited;
+end;
+
 end.