求助,难道程序运行时生成的控件都不能永久保存吗?
我想在程序运行时,动态生成一些panel、edit、label等,但这些控件好象不能永久保存,大家有办法吗?
请大家指点,谢谢!
[解决办法]
控件好象不能永久保存?是什么意思?你关闭程序内存释放后当然就消失了,,
或者你是创建控件后释放了些控件?
[解决办法]
动态生成的肯定是不能持久的,否则就用静态的
[解决办法]
动态生成的控件只是个变量而已,不能保存在可执行文件中的。
[解决办法]
想下次运行也自动生成,可以在关闭是保存相关属性到ini,下次运行时读取ini再自动生成
[解决办法]
既然动态的生成,还保存做什么,要保存也是保存他相关的属性。下次根据此属性来创建
[解决办法]
你的靜態控件是form創建的時候創建的,動態的是點擊按鈕生成的,只是看起來靜態控件已打開就有了而已
[解决办法]
关闭时 记录下动态生成的组件的属性 下次启动时再自动创建
[解决办法]
楼主,别听他们乱说。想动态保存很简单。我这里以Button为例给你写个。不过你给的这分也太少了,唉!
procedure TForm1.Button1Click(Sender: TObject);
var
aButton: TButton;
MS: TMemoryStream;
begin
aButton := TButton.Create(self);
aButton.Parent := Form1;
aButton.Caption := 'test';
Ms := TMemoryStream.Create;
Ms.WriteComponent(aButton);
Ms.SaveToFile('save.file');
Ms.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
aButton: TButton;
MS: TMemoryStream;
begin
Ms := TMemoryStream.Create;
Ms.LoadFromFile('save.file');
Ms.Position := 0;
aButton := TButton.Create(self);
aButton.Parent := Form1;
aButton := Ms.ReadComponent(aButton) as TButton;
Ms.Free;
end;
[解决办法]