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

📄 gentypedlists1.pas

📁 Delphi, typed list generator code snippled, wonderfull delphi sample code
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  FKnownMacros := TStringlist.Create;
  FUnknownMacros := TStringlist.Create;
  EvaluateCommandline;
  BuildMacrolists;
  SizeGrid;

  filename := ChangeFileExt(Application.Exename, '.HLP');
  if FileExists(filename) then
    Application.Helpfile := filename
  else
    HelpButton.Enabled := False;
end; { TTypedListgeneratorMainform.FormCreate }

{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform.
 |    Part 2. Methods that are triggered in response to user
 |            action
 |        2a. Button click handlers
 +============================================================}

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.CloseButtonClick
 |
 | Event      : OnClick
 | Used by    : CloseButton
 | Call method: static
 | Visibility : published
 | Description:
 |   Closes the form. There are no preconditions for the form
 |   to allow a close.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.CloseButtonClick(Sender:
  TObject);
begin
  Close;
end; {  TTypedListgeneratorMainform.CloseButtonClick  }

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.GenerateButtonClick
 |
 | Event      : OnClick
 | Used by    : GenerateButton
 | Call method: static
 | Visibility : published
 | Description:
 |   We first ask the user to select a directory where the generated
 |   unit is to be placed and then start the build process. The unit
 |   filename is the unit name with .PAS extension. If the file already
 |   exists the user is asked if it is OK to overwrite. He can cancel
 |   the build at this point.
 |   The generate button is always enabled since we cannot determine
 |   up front if one of the macros can be left empty or not, without
 |   loosing generality or complicating the macro syntax. The first
 |   thing the method does is call a validation method that will ask
 |   the user to confirm that any macros left blank are OK to use
 |   in this state. The effect of a blank macro will be that nothing
 |   of it remains in the produced unit. This is OK for a macro like
 |   USESCLAUSE but would be fatal for one like UNITNAME!
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.GenerateButtonClick(Sender:
  TObject);
var
  unitfile: string;
begin
  VerifyMacroInput;

  if DirectoryExists(cDefaultUnitDirectory) then
    unitfile := cDefaultUnitDirectory
  else
    unitfile := EmptyStr;

  if SelectDirectory(unitfile, [sdAllowCreate, sdPerformCreate], 0)
    then begin
    unitfile := unitfile + '\' + Macro('UNITNAME') + '.PAS';
    if FileExists(unitfile) then begin
      if MessageDlg(
        Format(cOverwritePrompt, [unitfile]),
        mtConfirmation, mbYesNoCancel, 0
        ) <> mrYes
        then
        Exit;
    end; { If }
  end; { If }
  BuildUnit(unitfile);
end; { TTypedListgeneratorMainform.GenerateButtonClick }

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.HelpButtonClick
 |
 | Event      : OnClick
 | Used by    : HelpButton
 | Call method: static
 | Visibility : published
 | Description:
 |   Calls up the helpfiles content page.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.HelpButtonClick(Sender: TObject);
begin
  Application.HelpCommand(HELP_CONTENTS, 0);
end; { TTypedListgeneratorMainform.HelpButtonClick }

{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform.
 |        2b. Menu click handlers
 |            none, the form does not have any menus.
 +============================================================}
{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform
 |    Part 2. Methods that are triggered in response to user
 |            action
 |        2c. Other control event handlers
 +============================================================}

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.ExPanel1Resize
 |
 | Event      : OnResize
 | Used by    : ExPanel1
 | Call method: static
 | Visibility : published
 | Description:
 |   We adjust the size of the right column of the MacroGrid here.
 |   The grid is client-aligned to the panel.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}

procedure TTypedListgeneratorMainform.ExPanel1Resize(Sender: TObject);
begin
  with MacroGrid do
    ColWidths[1] := ClientWidth - ColWidths[0] - 5;
end; { TTypedListgeneratorMainform.ExPanel1Resize }

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.UsePointersCheckboxClick
 |
 | Event      : OnClick
 | Used by    : UsePointersCheckbox
 | Call method: static
 | Visibility : published
 | Description:
 |   The two checkboxes UsePointersCheckbox and OwnsObjectCheckbox
 |   are mutually exclusive, only one can be checked. But both can
 |   be unchecked.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.UsePointersCheckboxClick(
  Sender: TObject);
begin
  if UsePointersCheckbox.Checked then
    OwnsObjectCheckbox.Checked := False;
end; { TTypedListgeneratorMainform.UsePointersCheckboxClick }

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.OwnsObjectCheckboxClick
 |
 | Event      : OnClick
 | Used by    : OwnsObjectCheckbox
 | Call method: static
 | Visibility : published
 | Description:
 |   The two checkboxes UsePointersCheckbox and OwnsObjectCheckbox
 |   are mutually exclusive, only one can be checked. But both can
 |   be unchecked.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.OwnsObjectCheckboxClick(
  Sender: TObject);
begin
  if OwnsObjectCheckbox.Checked then
    UsePointersCheckbox.Checked := False;
end; { TTypedListgeneratorMainform.OwnsObjectCheckboxClick }

{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform
 |    Part 3. Handlers For Windows messages
 |            none
 +============================================================}
{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform
 |    Part 4. Other event handlers
 +============================================================}

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.MacroGridDrawCell
 |
 | Event      : OnDrawCell
 | Used by    : MacroGrid
 | Call method: static
 | Visibility : published
 | Description:
 |   Draws the contents of the left column of the grid (the macro
 |   names) in boldface.
 | Error Conditions: none
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.MacroGridDrawCell(Sender:
  TObject;
  aCol, aRow: Integer; Rect: TRect; State: TGridDrawState);
begin
  if aCol = 0 then begin
    with (Sender as TStringGrid) do begin
      Canvas.Font.Style := [fsBold];
      Canvas.TextRect(Rect, Rect.Left + 4, Rect.Top + 2, Cells[0,
        aRow]);
      Canvas.Font.Style := [];
    end; { With }
  end; { If }
end; { TTypedListgeneratorMainform.MacroGridDrawCell }

{+============================================================
 | Section 2: Methods of TTypedListgeneratorMainform
 |    Part 5. Auxillary methods
 +============================================================}

{+------------------------------------------------------------
 | Procedure TTypedListgeneratorMainform.BuildUnit
 |
 | Parameters :
 |   unitfilename: full pathname of unitfile to generate
 | Call method: static
 | Visibility : private
 | Description:
 |   The method walks through the unit template line by line and
 |   replaces all macro strings found in the text by appropriate
 |   values. The generated lines are stored in a stringlist, which
 |   is finally written to a file with the passed name. The user
 |   is informed of the success of this operation.
 | Error Conditions:
 |   A EMacroError exception will be raised if the code finds a
 |   macro start delimiter but not a matching end delimiter in a
 |   line or if the passed unitfilename is empty.
 | Created: 03.06.99 by P. Below
 +------------------------------------------------------------}
procedure TTypedListgeneratorMainform.BuildUnit(
  const unitfilename: string);

  {+昄evel 2: Host TTypedListgeneratorMainform.BuildUnit晻晻晻

⌨️ 快捷键说明

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