我想做一个控件,用ActiveForm,这个可以吗??????上面放了一个TCheckListBoxk,用来控件Grid中列的显示与隐藏和字段显示顺序,我想把他做成一个控件,有一个TCustomGrid类型的私有成员变量,用Grid属性来访问它,但是为什么安装后没有Grid这个属性,听说要用Type Library来定义控件的属性,但如果用Type Library如何才能建一个Grid类型的成员呢????真的不明白,请大家帮帮忙,谢谢大侠了~~~~~

解决方案 »

  1.   

    你概念還比較亂, 建議看看
    <<delphi6 開發人員指南>>
    or
    <<delphi 參透>>
      

  2.   

    aiirii(ari-爱的眼睛):  你好~~~~我现在没有这方面的书,主要是下午要做出来。比较急,可以指点一下吗???真的很谢谢你~~~
      

  3.   

    在吗????怎么不回了???好急呀~~~~~贴出我的代码,让大侠们帮我找找毛病~~~~unit CheckListBoxGridx;interfaceuses
      SysUtils, Classes, Controls, StdCtrls, CheckLst;type    
      PStr = ^String;
      TArrayColumn = Array of TColumn;  TCheckListBoxGridx = class(TCheckListBox)
      private
        { Private declarations }
        FGrid  : TCustomGrid;
        FLockCols : TArrayColumn;
        FResult : Integer;
      protected
        { Protected declarations }
        function Get_Grid: TCustomGrid; safecall;
        function Get_LockCol : TArrayColumn;safecall;
        function Get_Result: Integer; safecall;
        function IsLock(FieldName : String) : Boolean;safecall;
        procedure Set_Grid(const AGrid : TCustomGrid); safecall;
        procedure Let_GridColList;safecall;
        procedure Set_LockCol(Columns : TArrayColumn);
        procedure Set_Result(AResult: Integer); safecall;
        procedure Set_GridCol;safecall;
      public
        { Public declarations }
      published
        { Published declarations }   
        procedure ColUp;safecall;
        procedure ColDown;safecall;
        property  Grid : TCustomGrid read Get_Grid write Set_Grid;
        property  Result : Integer read Get_Result write Set_Result;
      end;procedure Register;implementation
                    
    function TCheckListBoxGridx.Get_Grid: TCustomGrid;
    begin
      Result := FGrid;
    end;function TCheckListBoxGridx.Get_LockCol : TArrayColumn;
    begin
      Result := FLockCols;
    end;function TCheckListBoxGridx.Get_Result: Integer;
    begin
      Result := FResult;
    end;function TCheckListBoxGridx.IsLock(FieldName : String) : Boolean;
    var
      I : Integer;
    begin
      Result := True;
      for I := Low(FLockCols) to High(FLockCols) do
        if FieldName = TColumn(FLockCols[I]).FieldName then Exit;
      Result := False;
    end;
          
    procedure TCheckListBoxGridx.Set_Grid(const AGrid : TCustomGrid);
    begin
      if AGrid <> nil then
        FGrid := AGrid;
    end;procedure TCheckListBoxGridx.Let_GridColList;
    var
      I : Integer;
      AGridTemp : TDBGrid;
      P : PStr;
      ColCaption : String;
      ColVisible : Boolean;
    begin
      CLB_Col.Items.Clear;
      if FGrid = nil then Exit;
      AGridTemp := TDBGrid(FGrid);
      for I := 0 to AGridTemp.Columns.Count - 1 do
      begin
        New(P);
        P^ := AGridTemp.Columns[I].FieldName;
        ColCaption := AGridTemp.Columns[I].Title.Caption;
        ColVisible := AGridTemp.Columns[I].Visible;
        CLB_Col.Items.AddObject(ColCaption, TObject(P));
        CLB_Col.Checked[I] := ColVisible
      end;
    end;procedure TCheckListBoxGridx.Set_LockCol(Columns : TArrayColumn);
    begin
      FLockCols := Columns;
    end;procedure TCheckListBoxGridx.Set_Result(AResult: Integer);
    begin
      FResult := AResult;
      if FResult = 1 then
        Set_GridCol;
    end;procedure TCheckListBoxGridx.Set_GridCol;
    var
      AGridTemp : TDBGrid; 
      Col : TColumn;
      I : Integer;
    begin
      AGridTemp := TDBGrid(FGrid);
      AGridTemp.Columns.Clear;
      for I := 0 to CLB_Col.Items.Count - 1 do
      begin
        Col := AGridTemp.Columns.Add;
        Col.FieldName := String(PStr(CLB_Col.Items.Objects[I])^);
        Col.Title.Caption := CLB_Col.Items.Strings[I];
        AGridTemp.Columns[I].Visible := CLB_Col.Checked[I];
      end;
    end;procedure TCheckListBoxGridx.ColUp;
    var
      Source, Cause, CurrString : String;
      CurrObject : TObject;
    begin
      try
        with CLB_Col do
        begin
          if ItemIndex < 0 then Exit;
          CurrString := Items.Strings[ItemIndex];
          CurrObject := Items.Objects[ItemIndex];
          if IsLock(String(PStr(CurrObject)^)) then Exit;
          Items.Strings[ItemIndex] := Items.Strings[ItemIndex - 1];
          Items.Objects[ItemIndex] := Items.Objects[ItemIndex - 1];
          Items.Strings[ItemIndex - 1] := CurrString;
          Items.Objects[ItemIndex - 1] := CurrObject;
          ItemIndex := ItemIndex - 1;
        end;
      except
      end;
    end;procedure TCheckListBoxGridx.ColDown;
    var
      Source, Cause, CurrString : String;
      CurrObject : TObject;
    begin
      try
        with CLB_Col do
        begin
          if ItemIndex < 0 then Exit;
          if ItemIndex + 1 = Items.Count then Exit;
          CurrString := Items.Strings[ItemIndex];
          CurrObject := Items.Objects[ItemIndex];   
          if IsLock(String(PStr(CurrObject)^)) then Exit;
          Items.Strings[ItemIndex] := Items.Strings[ItemIndex + 1];
          Items.Objects[ItemIndex] := Items.Objects[ItemIndex + 1];
          Items.Strings[ItemIndex + 1] := CurrString;
          Items.Objects[ItemIndex + 1] := CurrObject; 
          ItemIndex := ItemIndex + 1;
        end;
      except
      end;
    end;procedure Register;
    begin
      RegisterComponents('Samples', [TCheckListBoxGridx]);
    end;end.
      

  4.   

    呵呵,其实代码看不看都没什么用,只是想知道怎么才能调用ActiveX中自定义的属性呢??现在改成用Component做的,编译时出错,无法通过编译。
    请大家帮帮忙说一下自己解决的办法或思路,感激.~~~~
      

  5.   

    把做好的保存然后从file-new-other..来继承