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

📄 ddhdbwiz.pas

📁 Delphi高级开发指南是开发程序的好帮手
💻 PAS
字号:
unit DdhDbWiz;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls, Grids, DB, DBTables, Buttons, Mask,
  DBCtrls, ExptIntf;

type
  TDdhDbFormWizard = class (TIExpert)
  public
    function GetStyle: TExpertStyle; override;
    function GetName: string; override;
    function GetComment: string; override;
    function GetGlyph: HICON; override;
    function GetState: TExpertState; override;
    function GetIDString: string; override;
    function GetMenuText: string; override;
    function GetAuthor: string; override;
    function GetPage: string; override;
    procedure Execute; override;
  end;

  TDdhDbFormWizard2 = class (TDdhDbFormWizard)
  public
    function GetStyle: TExpertStyle; override;
    function GetName: string; override;
    function GetIDString: string; override;
  end;

procedure Register;

implementation

uses
  IStreams, Proxies, ToolIntf, DdhDbwf;

{$R DBFWICON.RES}

function TDdhDbFormWizard.GetStyle: TExpertStyle;
begin
  Result := esStandard;
end;
function TDdhDbFormWizard2.GetStyle: TExpertStyle;
begin
  Result := esForm;
end;

function TDdhDbFormWizard.GetName: string;
begin
  Result := 'DDH DbForm Wizard'
end;
function TDdhDbFormWizard2.GetName: string;
begin
  Result := 'DDH DbForm Wizard 2'
end;

function TDdhDbFormWizard.GetComment: string;
begin
  Result := 'DbForm Wizard';
end;

function TDdhDbFormWizard.GetAuthor: string;
begin
  Result := 'Marco and Tim';
end;

function TDdhDbFormWizard.GetGlyph: HICON;
begin
  Result := LoadIcon (HInstance,
    MakeIntResource ('DBWFORM'));
end;

function TDdhDbFormWizard.GetPage: string;
begin
  Result := 'Forms';
end;

function TDdhDbFormWizard.GetState: TExpertState;
begin
  Result := [esEnabled];
end;

function TDdhDbFormWizard.GetIDString: string;
begin
  Result := 'DDHandbook.DbFormWizard'
end;
function TDdhDbFormWizard2.GetIDString: string;
begin
  Result := 'DDHandbook.DbFormWizard2'
end;

function TDdhDbFormWizard.GetMenuText: string;
begin
  Result := '&DbForm Wizard...'
end;

procedure TDdhDbFormWizard.Execute;
var
  FormName, UnitIdent, FileName: string;
  FormIStream, UnitIStream: TIMemoryStream;
  StrForm, StrUnit: TMemoryStream;
begin
  // get new form and unit names
  ToolServices.GetNewModuleAndClassName(
    'Form', UnitIdent, FormName, FileName);
  // create and show the main form of the wizard
  FormDbWiz := TFormDbWiz.Create (Application);
  try
    FormDbWiz.FormName := FormName;
    FormDbWiz.UnitName := UnitIdent;
    if FormDbWiz.ShowModal = mrOK then
    begin
      // create two streams
      StrUnit := TMemoryStream.Create;
      StrForm := TMemoryStream.Create;

      // save the string to the stream
      StrUnit.WriteBuffer (
        Pointer(FormDbWiz.SourceCode)^,
        Length (FormDbWiz.SourceCode));
      StrUnit.Position := 0;

      {copy the form to the second stream}
      // create a proxy
      Proxies.CreateSubclass (
        FormDbWiz.ResultForm, 'T' + FormName, TForm);
      // change the name
      FormDbWiz.ResultForm.Name := FormName;
      // write the form to a memory stream
      StrForm.WriteComponentRes (
        FormName, FormDbWiz.ResultForm);
      StrForm.Position := 0;

      // delete the form
      FormDbWiz.ResultForm.Free;
      FormDbWiz.ResultForm := nil;

      // create the two interface streams
      FormIStream := TIMemoryStream.Create (StrForm);
      UnitIStream := TIMemoryStream.Create (StrUnit);
      // let them own the actual streams
      FormIStream.OwnStream := True;
      UnitIStream.OwnStream := True;
      // create the new module
      ToolServices.CreateModule (
        FileName, UnitIStream, FormIStream,
        [cmAddToProject, cmShowSource, cmShowForm,
        cmUnnamed, cmMarkModified]);
    end;
  finally
    // free the main form
    FormDbWiz.Free;
  end;
end;

procedure Register;
begin
  RegisterLibraryExpert(TDdhDbFormWizard.Create);
  RegisterLibraryExpert(TDdhDbFormWizard2.Create);
end;

end.

⌨️ 快捷键说明

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