本帖最后由 rxf2006xz 于 2012-07-19 16:33:47 编辑

解决方案 »

  1.   

    按下列代码先设置好sgdForUnits的点击和画单元的事件,然后,将sgdUnits和sgdRectify的同名事件设置
    为sgdForUnits的事件名即可:
    ......
    type
      TF_FrameStringGrid = class(TFrame)
        GroupBox1: TGroupBox;
        sgdForUnits: TStringGrid;
        GroupBox2: TGroupBox;
        sgdUnits: TStringGrid;
        GroupBox3: TGroupBox;
        sgdRectify: TStringGrid;
        procedure sgdForUnitsClick(Sender: TObject);
        procedure sgdForUnitsDrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;implementation{$R *.dfm}procedure TF_FrameStringGrid.sgdForUnitsClick(Sender: TObject);
    begin
      TStringGrid(Sender).RowCount := TStringGrid(Sender).RowCount + 1;
    end;procedure TF_FrameStringGrid.sgdForUnitsDrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
      with TStringGrid(Sender).Canvas do begin
        Pen.Color := clRed;
        Brush.Style := bsClear;
        Rectangle(Rect);
      end;
    end;
    ......
      

  2.   

    调用时,将下列代码:
      F_BaseHiddenSet.Height := 656;
      F_BaseHiddenSet.Width := 763;
      F_DataModule.ADOTable1.TableName := 'HiddenSet';
      F_DataModule.ADOTable1.Open;  F_FrameStringGrid.sgdForUnits.Cells[0,0] := '被检单位';
      F_FrameStringGrid.sgdForUnits.Cells[1,0] := '负 责 人';  F_FrameStringGrid.sgdUnits.Cells[0,0] := '检查单位';
      F_FrameStringGrid.sgdUnits.Cells[1,0] := '负 责 人';  F_FrameStringGrid.sgdRectify.Cells[0,0] := '整改期限';
      F_FrameStringGrid.sgdRectify.Cells[1,0] := '整改结果';放在 F_BaseHiddenSet 的 Show 事件或 Create 事件中:procedure TF_BaseHiddenSet.FormCreate(Sender: TObject);
    begin
      Height := 656;
      Width := 763;
      F_DataModule.ADOTable1.TableName := 'HiddenSet';
      F_DataModule.ADOTable1.Open;
      F_FrameStringGrid:=TF_FrameStringGrid.Create(self);
      with F_FrameStringGrid do begin
        Parent:=F_BaseHiddenSet;
        sgdForUnits.Cells[0,0] := '被检单位';
        sgdForUnits.Cells[1,0] := '负 责 人';
        sgdUnits.Cells[0,0] := '检查单位';
        sgdUnits.Cells[1,0] := '负 责 人';
        sgdRectify.Cells[0,0] := '整改期限';
        sgdRectify.Cells[1,0] := '整改结果';
      end;
    end;
      

  3.   


    将这些代码放在FormCreate中不行,出现“Access violation at address 005F98BF in module 'AirManageSystem.exe'.Read of address 000002A0”。这是个什么错误,一般是什么原因导致的?
      

  4.   

    F_DataModule的建立可能在窗体之后了,请看看工程属性。
      

  5.   

    工程文件:program AirManageSystem;uses
      Forms,
      Main in 'Main.pas' {F_Main},
      Base in 'Base.pas' {F_BaseForm},
      DataModule in 'DataModule.pas' {F_DataModule: TDataModule},
      HiddenDanger in 'HiddenDanger.pas' {F_HiddenDanger},
      HiddenInput in 'HiddenInput.pas' {F_HiddenInput},
      FrameGroup in 'FrameGroup.pas' {F_FrameGroup: TFrame},
      FrameGroup2 in 'FrameGroup2.pas' {F_FrameGroupUnit: TFrame},
      InhFramGroup in 'InhFramGroup.pas' {F_InhFram_Group: TFrame},
      BaseSet in 'BaseSet.pas' {F_SystemSet},
      HiddenSet in 'HiddenSet.pas' {F_HiddenSet},
      BaseSystemSet in 'BaseSystemSet.pas' {F_BaseSystemSet},
      BaseHiddenSet in 'BaseHiddenSet.pas' {F_BaseHiddenSet},
      InhFramGroup2 in 'InhFramGroup2.pas' {F_FrameStringGrid: TFrame};{$R *.res}begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TF_Main, F_Main);
      Application.CreateForm(TF_BaseForm, F_BaseForm);
      Application.CreateForm(TF_DataModule, F_DataModule);
      Application.CreateForm(TF_HiddenDanger, F_HiddenDanger);
      Application.CreateForm(TF_HiddenInput, F_HiddenInput);
      Application.CreateForm(TF_SystemSet, F_SystemSet);
      Application.CreateForm(TF_HiddenSet, F_HiddenSet);
      Application.CreateForm(TF_BaseSystemSet, F_BaseSystemSet);
      Application.CreateForm(TF_BaseHiddenSet, F_BaseHiddenSet);
      Application.Run;
    end.窗体是F_BaseHiddenSet。
      

  6.   

    F_FrameStringGrid 是动态建立的,在引用它前,必须它的实例已经存在!
      

  7.   

    http://hi.baidu.com/%C3%BB%D0%C4%C3%BB%B7%CD/blog/item/9a7a76b4ff7022798bd4b2cd.html
    这个文章应该有帮助,不过需要一个个获取,LZ可以自己动动手