mainc.pas

来自「用.net开发AutoCAD生成dll文件。本程序可以启动AutoCAD并自动加」· PAS 代码 · 共 76 行

PAS
76
字号
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses ShellAPI, Registry, IniFiles;

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormShow(Sender: TObject);
var
  reg: TRegistry;
  sExeParam: string;
  sPath: string; //AcadLocation
  iniFile: TIniFile;
  sExePath: string;
  scr: TStrings;
begin
  sExePath := ExtractFilePath(Application.ExeName);
  iniFile := TIniFile.Create(sExePath + 'config.ini');
  sPath := iniFile.ReadString('Application', 'AcadLocation2008', '');

  if (sPath = '') or (not FileExists(sPath + '\ACAD.exe')) then
  begin
    reg := TRegistry.Create;
    reg.RootKey := HKEY_LOCAL_MACHINE;
    reg.OpenKey('SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:804', False);
    sPath := reg.ReadString('AcadLocation');
    reg.Free;
    iniFile.WriteString('Application', 'AcadLocation2008', sPath);
  end;
  if not FileExists(sPath + '\ACAD.exe') then
  begin
    Application.MessageBox(PChar('找不到AutoCAD 2008路径,请手动在config.ini文件添加。' + #13#10 +
      '将路径添加到AcadLocation项,' + #13#10 +
      '如 AcadLocation2008 = D:\Program Files\AutoCAD 2008'), PChar('提示'), MB_OK);
    Exit;
  end;
  scr := TStringList.Create;
  scr.Add('netload "' + sExePath + 'Quote.dll"');
  scr.SaveToFile(sExePath + 'start.scr');
  scr.Free;

  sExeParam := '"' + sPath + '\ACAD.exe" /p Quote /nologo ' +
    '/b "' + sExePath + 'start.scr' + '"';
  WinExec(PChar(sExeParam), SW_SHOWNORMAL);
  Timer1.Enabled := True;
end;

end.

⌨️ 快捷键说明

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