home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / QDB / QDBG.ZIP / qdbgreg.pas < prev    next >
Pascal/Delphi Source File  |  1998-07-29  |  5KB  |  175 lines

  1. unit qdbgreg;
  2.  
  3. interface
  4.  
  5. uses
  6.   DsgnIntf;
  7.  
  8. type
  9.   TQDBGridEditor = class(TComponentEditor)
  10.   public
  11.     function GetVerb(Index: Integer): string; override;
  12.     function GetVerbCount: Integer; override;
  13.     procedure ExecuteVerb(Index: Integer); override;
  14.   end;
  15.  
  16. procedure Register;
  17.  
  18. implementation
  19.  
  20. uses
  21.   SysUtils, Classes, Dialogs, Forms, TypInfo, Controls,
  22.   QDBView, QDBGrids, QDBGEdt;
  23.  
  24. (*
  25. {$IFDEF WIN32}
  26.   {$R QDBVREG.R32}
  27. {$ELSE}
  28.   {$R QDBVREG.R16}
  29. {$ENDIF}
  30. *)
  31.  
  32. function TQDBGridEditor.GetVerb(Index: Integer): string;
  33. begin
  34.   case Index of
  35.     0: Result:='Edit ' + Component.Name;
  36.     1: Result:='Load field defintions from QDB file';
  37.   else
  38.   end;
  39. end;
  40.  
  41. function TQDBGridEditor.GetVerbCount: Integer;
  42. var
  43.   t: TQDBItem;
  44. begin
  45.   Result:=0;
  46.   if (Component as TQDBGrid).QDBItem = nil then
  47.     Exit;
  48.   t:=TQDBItem.Create(nil);
  49.   try
  50.     t.ReadOnly:=true;
  51.     t.FileName:=(Component as TQDBGrid).QDBItem.Filename;
  52.     t.FetchStructure;
  53.     if t.FieldCount > 0 then
  54.       Result := 2;
  55.   finally
  56.     t.Free;
  57.   end;
  58. end;
  59.  
  60. type
  61.   THack = class(TQDBGrid);
  62.  
  63. procedure TQDBGridEditor.ExecuteVerb(Index: Integer);
  64. var
  65.   D: TQDBGridEditDlg;
  66.   t: TQDBItem;
  67.   x: TQDBItem;
  68.   n: integer;
  69.   wasreadonly: boolean;
  70. begin
  71.   case Index of
  72.     0:
  73.       begin
  74.         D := TQDBGridEditDlg.Create(Application);
  75.         try
  76.           with Component as TQDBGrid do
  77.           begin
  78.             D.Caption := Owner.Name + '.' + Name + D.Caption;
  79.             D.QDBGrid.Color:=Color;
  80.             D.QDBGrid.DefaultColWidth:=DefaultColWidth;
  81.             D.QDBGrid.DisplayThumbnails:=DisplayThumbnails;
  82.             D.QDBGrid.FixedColor:=FixedColor;
  83.             D.QDBGrid.Font:=Font;
  84.             D.QDBGrid.MatchRowHeightToFont:=MatchRowHeightToFont;
  85.             D.QDBGrid.Options:=Options + [QDBGrids.goSelectColumns];
  86.             D.QDBGrid.TitleFont:=TitleFont;
  87.             THack(D.QDBGrid).SetColumnCount(ColCount);
  88.             for n:=0 to Columns.Count-1 do
  89.             begin
  90.               D.QDBGrid.Columns[n].Alignment:=Columns[n].Alignment;
  91.               D.QDBGrid.Columns[n].ButtonStyle:=Columns[n].ButtonStyle;
  92.               D.QDBGrid.Columns[n].Color:=Columns[n].Color;
  93.               D.QDBGrid.Columns[n].DisplayMask:=Columns[n].DisplayMask;
  94.               D.QDBGrid.Columns[n].DropDownRows:=Columns[n].DropDownRows;
  95.               D.QDBGrid.Columns[n].EditMask:=Columns[n].EditMask;
  96.               D.QDBGrid.Columns[n].Font:=Columns[n].Font;
  97.               D.QDBGrid.Columns[n].LimitToList:=Columns[n].LimitToList;
  98.               D.QDBGrid.Columns[n].PickList:=Columns[n].PickList;
  99.               D.QDBGrid.Columns[n].ReadOnly:=Columns[n].ReadOnly;
  100.               D.QDBGrid.Columns[n].Title:=Columns[n].Title;
  101.               D.QDBGrid.Columns[n].TitleAlignment:=Columns[n].TitleAlignment;
  102.               D.QDBGrid.Columns[n].TitleFont:=Columns[n].TitleFont;
  103.               D.QDBGrid.ColWidths[n]:=ColWidths[n];
  104.             end;
  105.             D.QDBGrid.QDBItem:=QDBItem;
  106.             D.QDBGrid.QDBItem.FileName:=QDBItem.FileName;
  107.             wasreadonly:=QDBItem.ReadOnly;
  108.             D.QDBGrid.QDBItem.ReadOnly:=true;
  109.           end;
  110.           if D.ShowModal = mrOK then
  111.           begin
  112.             with Component as TQDBGrid do
  113.             begin
  114.               for n:=0 to Columns.Count-1 do
  115.               begin
  116.                 Columns[n].Alignment:= D.QDBGrid.Columns[n].Alignment;
  117.                 Columns[n].ButtonStyle:= D.QDBGrid.Columns[n].ButtonStyle;
  118.                 Columns[n].Color:= D.QDBGrid.Columns[n].Color;
  119.                 Columns[n].DisplayMask:= D.QDBGrid.Columns[n].DisplayMask;
  120.                 Columns[n].DropDownRows:= D.QDBGrid.Columns[n].DropDownRows;
  121.                 Columns[n].EditMask:= D.QDBGrid.Columns[n].EditMask;
  122.                 Columns[n].Font:= D.QDBGrid.Columns[n].Font;
  123.                 Columns[n].LimitToList:= D.QDBGrid.Columns[n].LimitToList;
  124.                 Columns[n].PickList:= D.QDBGrid.Columns[n].PickList;
  125.                 Columns[n].ReadOnly:= D.QDBGrid.Columns[n].ReadOnly;
  126.                 Columns[n].Title:= D.QDBGrid.Columns[n].Title;
  127.                 Columns[n].TitleAlignment:= D.QDBGrid.Columns[n].TitleAlignment;
  128.                 Columns[n].TitleFont:= D.QDBGrid.Columns[n].TitleFont;
  129.                 ColWidths[n]:= D.QDBGrid.ColWidths[n];
  130.               end;
  131.               QDBItem.ReadOnly:=wasreadonly;
  132.             end;
  133.             Designer.Modified;
  134.           end;
  135.         finally
  136.           D.Free;
  137.         end;
  138.      end;
  139.     1:
  140.       begin
  141.         t:=TQDBItem.Create(nil);
  142.         try
  143.           with (Component as THack) do
  144.           begin
  145.             x:=QDBItem;
  146.             QDBItem:=t;
  147.             QDBItem.FileName:=x.FileName;
  148.             QDBItem.FetchStructure;
  149.             THack(Component).SetColumnCount(FixedCols + QDBItem.FieldCount);
  150.             for n:=0 to FixedCols-1 do
  151.             begin
  152.               Columns[n].Title:='';
  153.             end;
  154.             for n:=FixedCols to Columns.Count-1 do
  155.             begin
  156.               Columns[n].Title:=QDBItem.FieldNames[n-FixedCols];
  157.             end;
  158.             QDBItem:=x;
  159.           end;
  160.          finally
  161.            t.Free;
  162.          end;
  163.       end;
  164.   else
  165.   end;
  166. end;
  167.  
  168. procedure Register;
  169. begin
  170.   RegisterComponents('IHSoftware', [TQDBGrid]);
  171.   RegisterComponentEditor(TQDBGrid,TQDBGridEditor);
  172. end;
  173.  
  174. end.
  175.