⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.pas

📁 delphi 写的delphi的程序 Handel is a free, standalone development tool created with Delphi 3 that enable
💻 PAS
📖 第 1 页 / 共 5 页
字号:

   ProxyDesigner := TProxyDesigner.Create(self);
end;

procedure TFMainForm.FileExitItemClick(Sender: TObject);
begin
   Close;
end;

procedure TFMainForm.FormShow(Sender: TObject);
var
   I:Integer;
   FileName:string;
begin
   ObjectInspector.Show;
   EditorForm.Show;
   NewProject;
   // if exists parameters, then open the file
   if ParamCount>0 then
   begin
      for I:=1 to ParamCount do
          FileName:= FileName + ' ' + ParamStr(I);
      if FileExists(ParamStr(1)) then OpenFile(ParamStr(1))
      else OpenFile(Trim(FileName));
   end;
   ReadEnvirionment;
end;

procedure TFMainForm.HelpAboutItemClick(Sender: TObject);
begin
   CreateShowModal(TAboutBox);
end;

procedure TFMainForm.sbButtonClick(Sender: TObject);
var
  st:Integer;
begin
   SelectedComponentName:=(Sender as TSpeedButton).Hint;
   st:=GetKeyState(VK_SHIFT);
   if SelectedComponentName = '' then ShiftKeyed:= False
   else if st < 0 then ShiftKeyed:= True
   else ShiftKeyed:= False;
end;

procedure TFMainForm.sbOpenFileClick(Sender: TObject);
begin
   OpenDialog1.Title := 'Open';
  { OpenDialog1.Filter:= 'Delphi Files(*.pas;*.dpr)|*.pas;*.dpr'+
                         '|Delphi Project(*.dpr)|*.dpr'+
                         '|Delphi Unit(*.pas)|*.pas'+
                         '|Delphi Form(*.dfm)|*.dfm'+
                         '|Text File(*.txt)|*.txt'+
                         '|All Files (*.*)|*.*';}
   OpenDialog1.InitialDir := IniFile.ReadString('system', 'LastPath',FilePath);
   OpenDialog1.FilterIndex:= 1;
   if OpenDialog1.Execute then
   begin
      IniFile.WriteString('system', 'LastPath',ExtractFilePath(OpenDialog1.FileName));
      OpenFile(OpenDialog1.FileName);
   end;
end;

procedure TFMainForm.sbFormsClick(Sender: TObject);
var
   FormName:string;
begin
   // show form list in project
   with TViewForm.Create(self) do
   begin
       Caption:= 'View Form';
       FileList.Items.Assign(ProjectInfo.FormItems);
       if ShowModal <> mrCancel then
       begin
          FormName:= GetUnitName(FileName.Text);
          OpenFile(FormName);
       end;
       Free;
   end;
end;

procedure TFMainForm.sbUnitsClick(Sender: TObject);
var
   I:Integer;
begin
   // show unit list in project
   with TViewForm.Create(self) do
   begin
       Caption:= 'View Unit';
       FileList.Items.Clear;
       for I:= 0 to ProjectInfo.UnitItems.Count -  1 do
          FileList.Items.Add(GetNetFileName(ProjectInfo.UnitItems[I]));
       if ShowModal <> mrCancel then
          OpenFile(ProjectInfo.ProjectPath+FileName.Text+'.pas');
       Free;
   end;
end;

procedure TFMainForm.OpenFile(const FileName:string);
var
   Index:Integer;
   Ext:string;
begin
   if not FileExistOnPath(FileName) then  Exit;
   Ext:= ExtractFileExt(FileName);
   Index:= IsOpenedFile(FileName);  // check filename is already opened
   if Index <> -1 then
   begin
      EditorForm.PageControl1.ActivePage:= PageControl1.Pages[Index];
      Screen.Cursor:= crDefault;
      Exit;
   end;
   if Ext = '.dpr' then CreateSheet(FileName)
   // open form as text
   else if Ext = '.dfm' then OpenFormAsText(FileName)
   else if Ext = '.pas' then
   begin
      CreateSheet(FileName);
      OpenForm(Copy(FileName,1,Length(FileName)-3)+'dfm');
   end
   else CreateSheet(FileName);
   SaveFileHistory(FileName);
end;

procedure TFMainForm.ViewProjectSourceItemClick(Sender: TObject);
var
   Index:Integer;
   FileName:string;
begin
   FileName:= ProjectInfo.ProjectName;
   Index:= IsOpenedFile(FileName);
   if Index <> -1 then
   begin
      EditorForm.PageControl1.ActivePage:= PageControl1.Pages[Index];
      Screen.Cursor:=crDefault;
      Exit;
   end;
   CreateSheet(FileName);
end;

// open project
procedure TFMainForm.sbOpenProjectClick(Sender: TObject);
begin
   FileOpenProjectItemClick(self);
end;

procedure TFMainForm.ViewProjectManagerItemClick(Sender: TObject);
begin
   with TProjectManager.Create(self) do
   begin
      GetProjectInfo;
      Show;
   end;
end;

procedure TFMainForm.ProjectCompileItemClick(Sender: TObject);
// Compile project
begin
   if IniFile.ReadBool('SYSTEM','DefaultCompiler',True) then
      CompileAndInformation('/M')
   else CompileAndInformation(IniFile.ReadString('Compiler','OtherOption', ''));
end;

procedure TFMainForm.ProjectBuildAllItemClick(Sender: TObject);
begin
   CompileAndInformation('/B');
end;

procedure TFMainForm.RunRunItemClick(Sender: TObject);
// compile and run project
var
   ret:integer;
   ExeName:string;
begin
   if Compile(ProjectInfo.ProjectName, '/M') then
   begin
      ExeName:= Copy(ProjectInfo.ProjectName,1,Length(ProjectInfo.ProjectName)-3)+'exe';
      ret:= WinExec(PChar(ExeName), SW_SHOWNORMAL);
      if ret < 31 then MessageDlg('Cannot Execute ' + ExtractFileName(ExeName)+'!', mtError, [mbOK], 0);
   end;
end;

procedure TFMainForm.SaveForm(Form:TForm;FormName:string);
// save form file
var
   I:Integer;
begin
   Form.OnActivate := nil;
   Form.OnCreate   := nil;
   Form.OnDestroy  := nil;
   Form.OnMouseDown:= nil;
   Form.OnMouseMove:= nil;
   Form.OnMouseUp  := nil;
   Form.OnResize   := nil;
   Form.OnPaint    := nil;
   for I:= Form.ComponentCount - 1 downto 0 do
   begin
      if ProxyDesigner.IsDesignedComponent(Form.Components[I]) then
         Form.Components[I].Free
      else if Form.Components[I].Name = 'ProxyPopupMenu1' then Form.Components[I].Free
   end;
   WriteDFM(Form, FormName);
   Form.Free;
   OpenForm(FormName);
end;

function TFMainForm.CreateForm(const FormName,UnitName:string):TForm;
// Create proxy form
begin
   Result:= CreateProxy(TProxyForm, 'T' + GetNetFileName(FormName)) as TForm;
   with Result do
   begin
      BorderStyle:= bsSizeable;
      Caption    := GetNetFileName(FormName);
      Name       := GetNetFileName(FormName);
      ActiveUnit := UnitName;
      TProxyForm(Result).FileName:= UnitName;
      Show;
      TExposeComponent(Result).SetDesigning(True);
      ActiveForm := Result;
   end;
end;

procedure TFMainForm.CreateSheet(const FileName:string);
// Create tabsheet, editor with filename
var
   PasEditor:TmwCustomEdit;
   TabSheet:TTabSheet;
   List:TStringList;
begin
   Inc(UnitCount);
   if UnitCount > 255 then
   begin
      ShowMessage('exceed maximum editor count(255)!');
      Exit;
   end;
   TabSheet:= TTabSheet.Create(EditorForm.PageControl1);
   with TabSheet do
   begin
      PageControl := EditorForm.PageControl1;
      if ExtractFileExt(FileName)='.pas' then
           Caption:= GetNetFileName(FileName)
      else Caption:= ExtractFileName(FileName);
      PasEditor                       := TmwCustomEdit.Create(EditorForm.PageControl1);
      PasEditor.Parent                := TabSheet;
      PasEditor.Name                  := UniqueName(PasEditor);
      PasEditor.Color                 := IniFile.ReadInteger('EditorColor','WhiteSpace', clWhite);
      PasEditor.Font.Name             := IniFile.ReadString('EDITOR','FONTNAME','Courier New');
      PasEditor.Font.Size             := IniFile.ReadInteger('EDITOR','FONTSIZE',10);
      PasEditor.Gutter.AutoSize       := True;
      PasEditor.Gutter.ShowLineNumbers:= ViewLineNumberItem.Checked;
      PasEditor.Gutter.LeftOffset     := 2;
      PasEditor.Gutter.Visible        := True;
      PasEditor.Align                 := alClient;
      PasEditor.PopupMenu             := EditorForm.EditorLocalMenu;
      PasEditor.ScrollBars            := ssBoth;
      PasEditor.HighLighter           := EditorForm.PasSyn;
      PasEditor.Tag                   := UnitCount;
     // PasEditor.OnKeyUp               := EditorForm.PasEditorKeyUp;
      PasEditor.OnStatusChange        := EditorForm.StatusChangeHandler;
      if ExtractFileExt(FileName)='.dpr' then
      begin
      // create new project code
         PasEditor.Lines.Assign(ProjectInfo.ProjectSource);
      end
      else if not FileExistOnPath(FileName) then
      begin
      // create new unit source code
         List:= TStringList.Create;
         List:= CreateDefaultUnit(List,GetNetFileName(FileName),
               'Form'+FileName[Length(FileName)-4]);
         PasEditor.Lines.Assign(List);
         List.Free;
         EditorForm.MwCompletionProposal1.Editor:= PasEditor;
         EditorForm.mwAutoComplete1.Editor:= PasEditor;
      end
      else if ExtractFileExt(FileName)='.pas' then
      begin
         if IniFile.ReadBool('EDITOR','HighLight',True) then
         begin
            PasEditor.HighLighter:= EditorForm.PasSyn;
            PasEditor.Lines.LoadFromFile(FileName);
            EditorForm.MwCompletionProposal1.Editor:= PasEditor;
            EditorForm.mwAutoComplete1.Editor:= PasEditor;
         end
         else
         begin
            PasEditor.HighLighter:= nil;
            PasEditor.Lines.LoadFromFile(FileName);
         end;
         PasEditor.Modified:= False;
      end
      else  PasEditor.Lines.LoadFromFile(FileName);
   end;
   OpenUnitList[UnitCount].FileName:= FileName;
   OpenUnitList[UnitCount].Editor:= PasEditor;
   EditorForm.Caption:= ExtractFileName(FileName);
   EditorForm.PageControl1.ActivePage:=TabSheet;
   EditorForm.Show;
   ActivePasEditor:= PasEditor;
end;

procedure TFMainForm.CreateSheetAsStream(const FileName:string;Stream:TStream);
// 叼胶农 惑俊 粮犁窍瘤 臼绊 , Stream俊 历厘等 郴侩阑 免仿茄促.
var
   PasEditor:TmwCustomEdit;
   TabSheet:TTabSheet;
begin
   TabSheet:=TTabSheet.Create(EditorForm.PageControl1);
   with TabSheet do
   begin
      PageControl          := EditorForm.PageControl1;
      Caption              := ExtractFileName(FileName);
      PasEditor            := TmwCustomEdit.Create(EditorForm.PageControl1);
      PasEditor.Parent     := TabSheet;
      PasEditor.Name       := UniqueName(PasEditor);
      PasEditor.Color      := IniFile.ReadInteger('EditorColor', 'WhiteSpace', clWhite);
      PasEditor.Font.Name  := IniFile.ReadString ('EDITOR'     , 'FONTNAME'  , 'Courier New');
      PasEditor.Font.Size  := IniFile.ReadInteger('EDITOR'     , 'FONTSIZE'  , 10);
      PasEditor.Align      := alClient;
      PasEditor.PopupMenu  := EditorForm.EditorLocalMenu;
      PasEditor.ScrollBars := ssBoth;
      PasEditor.HighLighter:= EditorForm.PasSyn;
      if IniFile.ReadBool('EDITOR','HighLight',False) then
      begin
         PasEditor.HighLighter:= EditorForm.PasSyn;
         PasEditor.Lines.LoadFromStream(Stream);
      end
      else
      begin
         PasEditor.HighLighter:= nil;
         PasEditor.Lines.LoadFromStream(Stream);
      end;
      PasEditor.Modified:= False;
   end;
   EditorForm.Caption:= ExtractFileName(FileName);
   EditorForm.PageControl1.ActivePage:=TabSheet;
   EditorForm.Show;
   ActivePasEditor:=PasEditor;
end;

procedure TFMainForm.sbMainMenuClick(Sender: TObject);
begin
   MsgDlg('Sorry! Not implement yet!', Application.Title, MB_OK);
end;

procedure TFMainForm.EditCopyItemClick(Sender: TObject);
begin
   if ActivePasEditor.SelText <> '' then
   begin
      ActivePasEditor.CopyToClipboard;
      EditorForm.Show;
   end
   else  ProxyDesigner.CopyComponent;
end;

procedure TFMainForm.EditPasteItemClick(Sender: TObject);
begin
   if not ClipBoard.HasFormat(CF_COMPONENT) then
   begin
      ActivePasEditor.PasteFromClipboard;
      EditorForm.Show;
   end
   else ProxyDesigner.PasteComponent;
end;

procedure TFMainForm.EditCutItemClick(Sender: TObject);
begin
   if ActivePasEditor.SelText <> '' then
   begin
     ActivePasEditor.CutToClipboard;
     EditorForm.Show;
   end
   else ProxyDesigner.CutComponent;
end;

procedure TFMainForm.FileSaveItemClick(Sender: TObject);
begin
   SaveFile(ActiveUnit);
end;

procedure TFMainForm.FilePrintItemClick(Sender: TObject);
begin
   CreateShowModal(TPrintSelDlg);
end;

procedure TFMainForm.EditSelectAllItemClick(Sender: TObject);
begin
   if ToggleFormUnit then
   begin
      if ProxyDesigner <> nil then  ProxyDesigner.SelectAll;
   end
   else
   begin
     ActivePasEditor.SelectAll;
     EditorForm.Show;
   end;
end;

procedure TFMainForm.EditUndoItemClick(Sender: TObject);
begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -