我用writecomponent()保存TStringGrid控件,用readcomponent()读出,
出现错误:property TInplaceEdit not found.
  请问该如何解决?是不是保存的时候连property TInplaceEdit也要写入文件,但是TInplaceEdit是什么东西,指的是StringGrid的cell吗?怎么得到它呢?

解决方案 »

  1.   

    提供GRID的文本编辑能力的东西!
      

  2.   

    这个问题还比较麻烦,我用google搜索居然找不到中文网页关于TStringGrid和TInPlaceEdit的信息基本上知道了TInPlaceEdit是什么,但是还是不明白它和TStringGrid的关系,能用
    TStringGrid1.controls[i]这样的形式获得TInPlaceEdit吗?请教高手,解决了问题再加分吧,原来低估这个问题了
      

  3.   

    TInPlaceEdit 是一个编辑网格的文本编辑器.用TStringGrid1.controls[i]应该取不到TinplaceEdit.
      

  4.   

    问题1:用S.writecomponent()保存TStringGrid控件,用S.readcomponent()读出,
    出现错误:property TInplaceEdit not found.
    请问该如何解决?是不是保存的时候连property TInplaceEdit也要写入文件?
    (S : TStream;)
    问题2:基本上知道了TInPlaceEdit是什么,但是还是不明白它和TStringGrid的关系,能用
    TStringGrid1.controls[i]这样的形式获得TInPlaceEdit吗?(好像不能),那么如何才能获得TInPlaceEdit呢?
      

  5.   

    我试过了,保存StringGrid控件没有问题,就用我曾经给你写的方法就行。以下是关于动态保存与生成StringGrid控件的代码:
    先动态建一个StringGrid控件:
    var
      AStringGrid: TStringGrid;
    begin
      AStringGrid := TStringGrid.Create(Self);
      AStringGrid.Parent := Form1.RichEditNew;
      AStringGrid.Width := 200;
      AStringGrid.Height := 100;
    end;
    然后进行保存:
    procedure TForm1.BtnSaveClick(Sender: TObject);
    var
      S: TStream;
      i: Integer;
      tmpFileName: String;
    begin
      if SaveDialog1.Execute then
      begin
        tmpFileName := SaveDialog1.FileName;
        // 保存元件到文件    S := TFileStream.Create(tmpFileName, fmCreate);  
        try
          S.WriteComponent(RichEditNew);
          for i := 0 to RichEditNew.ControlCount - 1 do
          begin
            if RichEditNew.Controls[i] is TStringGrid then
              S.WriteComponent(TStringGrid(RichEditNew.Controls[i]));
          end;
        finally
          S.Free;
        end;
      end;
    end;
    然后再从新载入:
    procedure TForm1.BtnOpenClick(Sender: TObject);
    var
      S: TStream;
      i: Integer;  StringGrid: TStringGrid;
    begin
      if OpenDialog1.Execute then
      begin
        for i := 0 to RichEditNew.ControlCount - 1 do
        begin
          RichEditNew.Controls[0].Free;
        end;    tmpFileName := OpenDialog1.FileName;    S := TFileStream.Create(tmpFileName, fmOpenRead); 
        S.ReadComponent(RichEditNew);    StringGrid := TStringGrid.Create(Self);
        StringGrid.Parent := RichEditNew;
        StringGrid.Name := 'StringGrid1';
        S.ReadComponent(StringGrid);
        StringGrid.Width := 200;
        StringGrid.Height := 100;    S.Free;
      end;
    end;
      

  6.   

    sorry,我没有测详细,我存取stringgrid的时候没有赋表格值,所以没有出现TInplaceEdit,后来发现了,sorry-_-!
      

  7.   

    是啊,按你那样写法是没有问题的^^
    但是如果写成这样:var
      AStringGrid: TStringGrid;
    begin
      AStringGrid := TStringGrid.Create(Self);
      AStringGrid.Parent := Form1.RichEditNew;
      AStringGrid.Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goRowMoving, goColMoving, goEditing, goTabs, goAlwaysShowEditor];//这是特别关键的地方!
      AStringGrid.Width := 200;
      AStringGrid.Height := 100;
    end;
    然后进行保存/载入就有问题出现啦!
      

  8.   

    按下面的做就可以搞定啦:
    Uses *************************, Grids;
    initialization
    RegisterClasses([**********************, TInplaceEdit]);
    放在 Pas单元最后一个 end. 的上面就是啦,
    >> 知道TInPlaceEdit是什么,但是不明白它和TStringGrid的关系
      TStringGrid的编辑控件。
    >> TStringGrid1.controls[i]这样的形式获得TInPlaceEdit吗?
      可以肯定是能的,判断他是不是 TInplaceEdit就是啦,因为他在建立时的 Parent:= Self 啦,
    >> 那么如何才能获得TInPlaceEdit呢?
      派生一个基于TStringGrid至 TCustomDraw的类,如TMyGrid= Class(TCustomDraw); ,然后用 TMyGrid(TStringGrid).InplaceEditor 就可以调用到他啦, 不过能建立他也是有前提的啦,他可不是Create时建立的哦,