home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d123456 / DFS.ZIP / VInfoReg.pas < prev   
Pascal/Delphi Source File  |  2001-06-28  |  6KB  |  243 lines

  1. {$I DFS.INC}
  2.  
  3. unit VInfoReg;
  4.  
  5. interface
  6.  
  7. {$IFDEF DFS_WIN32}
  8.   {$R VERSINFO.RES}
  9. {$ELSE}
  10.   {$R VERSINFO.R16}
  11. {$ENDIF}
  12.  
  13.  
  14. procedure Register;
  15.  
  16. implementation
  17.  
  18. uses
  19.   {$IFDEF DFS_NO_DSGNINTF}
  20.   DesignIntf,
  21.   DesignEditors,
  22.   {$ELSE}
  23.   DsgnIntf,
  24.   {$ENDIF}
  25.   VersInfo, DFSAbout, Classes, TypInfo, StdCtrls, Forms,
  26.   {$IFDEF DFS_WIN32} ComCtrls, {$ELSE} Grids, {$ENDIF}
  27.   {$IFDEF DFS_COMPILER_5_UP}
  28.   Contnrs,
  29.   {$ENDIF}
  30.   Controls, Dialogs;
  31.  
  32. type
  33. {--- Version editor -----------------------------------------------------------}
  34. { double click opens the filename edit dialog }
  35. { right click gives two options - show the resources in a grid now }
  36. { and edit the filename }
  37.   TVersionEditor = class(TDefaultEditor)
  38.     procedure Edit; override;
  39.     {$IFDEF DFS_IPROPERTY}
  40.     procedure EditProp(const Prop: IProperty);
  41.     {$ELSE}
  42.     procedure EditProp(Prop: TPropertyEditor);
  43.     {$ENDIF}
  44.     procedure ExecuteVerb(Index: Integer); override;
  45.     function GetVerb(Index: Integer): string; override;
  46.     function GetVerbCount: Integer; override;
  47.   private
  48.     procedure ShowVersInfoForm(const Filename: string);
  49.   end;
  50.  
  51. {--- filename property editor .. fileopen dialog box --------------------------}
  52.   TVersionFilenameProperty = class (TStringProperty)
  53.   public
  54.     procedure Edit; override;
  55.     function GetAttributes: TPropertyAttributes; override;
  56.   end;
  57.  
  58. procedure TVersionFilenameProperty.Edit;
  59. begin
  60.   with TOpenDialog.Create(Application) do
  61.   begin
  62.     Filename := GetValue;
  63.     Filter := 'Executables (*.exe)|*.exe|' +
  64.               'Libraries (*.dll)|*.dll|' +
  65.               'Packages (*.dpl)|*.dpl|' +
  66.               'Drivers (*.drv,*.386,*.vxd)|*.drv;*.386;*.vxd|' +
  67.               'Any file (*.*)|*.*';
  68.     Options := Options + [ofPathMustExist, ofFileMustExist, ofHideReadOnly];
  69.     try
  70.       if Execute then
  71.         SetValue(Filename)
  72.     finally
  73.       Free
  74.     end
  75.   end
  76. end;
  77.  
  78.  
  79. function TVersionFilenameProperty.GetAttributes: TPropertyAttributes;
  80. begin
  81.   Result := [paDialog {$IFDEF DFS_WIN32}, paRevertable {$ENDIF}]
  82. end;
  83.  
  84. procedure TVersionEditor.Edit;
  85. var
  86.   {$IFDEF DFS_DESIGNERSELECTIONS}
  87.   Components: IDesignerSelections;
  88.   {$ELSE}
  89.   {$IFDEF DFS_COMPILER_5_UP}
  90.   Components: TDesignerSelectionList;
  91.   {$ELSE}
  92.   Components: TComponentList;
  93.   {$ENDIF}
  94.   {$ENDIF}
  95. begin
  96.   {$IFDEF DFS_DESIGNERSELECTIONS}
  97.   Components := CreateSelectionList;
  98.   {$ELSE}
  99.   {$IFDEF DFS_COMPILER_5_UP}
  100.   Components := TDesignerSelectionList.Create;
  101.   {$ELSE}
  102.   Components := TComponentList.Create;
  103.   {$ENDIF}
  104.   {$ENDIF}
  105.   try
  106.     Components.Add(Component);
  107.     GetComponentProperties(Components, tkAny, Designer, EditProp)
  108.   finally
  109.     {$IFNDEF DFS_DESIGNERSELECTIONS}
  110.       Components.Free;
  111.     {$ENDIF}
  112.   end
  113. end;
  114.  
  115. procedure TVersionEditor.EditProp(
  116.   {$IFDEF DFS_IPROPERTY}
  117.   const Prop: IProperty
  118.   {$ELSE}
  119.   Prop: TPropertyEditor
  120.   {$ENDIF}
  121. );
  122. begin
  123.   {$IFDEF DFS_IPROPERTY}
  124.   Prop.Edit;
  125.   Designer.Modified;
  126.   {$ELSE}
  127.   if Prop is TVersionFilenameProperty then
  128.   begin
  129.     TVersionFilenameProperty(Prop).Edit;
  130.     Designer.Modified
  131.   end
  132.   {$ENDIF}
  133. end;
  134.  
  135. procedure TVersionEditor.ShowVersInfoForm(const Filename: string);
  136. var
  137.   Frm: TForm;
  138.   btnClose: TButton;
  139.   VerInfo: TdfsVersionInfoResource;
  140.   VersionDisplay: {$IFDEF DFS_WIN32} TListView {$ELSE} TStringGrid {$ENDIF};
  141. begin
  142.   Frm := TForm.Create(Application);
  143.   try
  144.     Frm.BorderStyle := bsDialog;
  145.     Frm.Caption := 'Version Info';
  146.     Frm.Position := poScreenCenter;
  147.     Frm.SetBounds(0, 0, 384, 238);
  148.     btnClose := TButton.Create(frm);
  149.     btnClose.Parent := Frm;
  150.     btnClose.SetBounds(147, 180, 80, 25);
  151.     btnClose.Cancel := TRUE;
  152.     btnClose.Caption := '&Close';
  153.     btnClose.Default := True;
  154.     btnClose.ModalResult := mrOK;
  155.     VerInfo := TdfsVersionInfoResource.Create(Frm);
  156.     VerInfo.Filename := Filename;
  157.  
  158.     {$IFDEF DFS_WIN32}
  159.     VersionDisplay := TListView.Create(Frm);
  160.     with VersionDisplay do
  161.     begin
  162.       Parent := Frm;
  163.       Left := 8;
  164.       Top := 8;
  165.       Width := 358;
  166.       Height := 164;
  167.       ColumnClick := FALSE;
  168.       with Columns.Add do
  169.       begin
  170.         Caption := 'Resource';
  171.         Width := 85;
  172.       end;
  173.       with Columns.Add do
  174.       begin
  175.         Caption := 'Value';
  176.         Width := 265;
  177.       end;
  178.       ReadOnly := True;
  179.       TabOrder := 0;
  180.       ViewStyle := vsReport;
  181.     end;
  182.     VerInfo.VersionListView := VersionDisplay;
  183.     {$ELSE}
  184.     VersionDisplay := TStringGrid.Create(Frm);
  185.     with VersionDisplay do
  186.     begin
  187.       Parent := Frm;
  188.       Left := 8;
  189.       Top := 8;
  190.       Width := 358;
  191.       Height := 164;
  192.       ColCount := 2;
  193.       FixedCols := 0;
  194.       FixedRows := 0;
  195.       Options := [goDrawFocusSelected, goColSizing, goRowSelect];
  196.       TabOrder := 0;
  197.       ColWidths[0] := 85;
  198.       ColWidths[1] := 265;
  199.     end;
  200.     VerInfo.VersionGrid := VersionDisplay;
  201.     {$ENDIF}
  202.  
  203.     Frm.ShowModal;
  204.   finally
  205.     { Everything created above is owned by Frm, so it will free them. }
  206.     Frm.Free;
  207.   end;
  208. end;
  209.  
  210. procedure TVersionEditor.ExecuteVerb(Index: Integer);
  211. begin
  212.   case Index of
  213.     0 : ShowVersInfoForm(TdfsVersionInfoResource(Component).Filename);
  214.     1 : Edit;
  215.   end
  216. end;
  217.  
  218. function TVersionEditor.GetVerb(Index: Integer): string;
  219. begin
  220.   case Index of
  221.     0 : Result := 'Show Version Info';
  222.     1 : Result := 'Set Filename';
  223.   end
  224. end;
  225.  
  226. function TVersionEditor.GetVerbCount: Integer;
  227. begin
  228.   Result := 2
  229. end;
  230.  
  231.  
  232. procedure Register;
  233. begin
  234.   RegisterComponents('DFS', [TdfsVersionInfoResource]);
  235.   RegisterPropertyEditor(TypeInfo(TVersionFilename), NIL, '',
  236.      TVersionFilenameProperty);
  237.   RegisterPropertyEditor(TypeInfo(string), TdfsVersionInfoResource, 'Version',
  238.      TDFSVersionProperty);
  239.   RegisterComponentEditor(TdfsVersionInfoResource, TVersionEditor);
  240. end;
  241.  
  242. end.
  243.