我用writecomponent()保存TStringGrid控件,用readcomponent()读出,
出现错误:property TInplaceEdit not found.
请问该如何解决?是不是保存的时候连property TInplaceEdit也要写入文件,但是TInplaceEdit是什么东西,指的是StringGrid的cell吗?怎么得到它呢?
出现错误:property TInplaceEdit not found.
请问该如何解决?是不是保存的时候连property TInplaceEdit也要写入文件,但是TInplaceEdit是什么东西,指的是StringGrid的cell吗?怎么得到它呢?
TStringGrid1.controls[i]这样的形式获得TInPlaceEdit吗?请教高手,解决了问题再加分吧,原来低估这个问题了
出现错误:property TInplaceEdit not found.
请问该如何解决?是不是保存的时候连property TInplaceEdit也要写入文件?
(S : TStream;)
问题2:基本上知道了TInPlaceEdit是什么,但是还是不明白它和TStringGrid的关系,能用
TStringGrid1.controls[i]这样的形式获得TInPlaceEdit吗?(好像不能),那么如何才能获得TInPlaceEdit呢?
先动态建一个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;
但是如果写成这样: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;
然后进行保存/载入就有问题出现啦!
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时建立的哦,