Yes, this question is too hard. You know, Windows API don't know the class in the VCL. But Delphi know. In all advance, you have to know how many types of class you could create. And for every class create a entry. And then use the CASE statement to create the class. I know this way is very simply and maybe can't help you. But it's the best way I can think.you can record, for example, as following
class=tedit
width=20
high=12
top=23
left=34
.
.
.
and in you program, you can do as followingif compare(class, 'tedit')=0 then
begin
cls:=TEdit.Create(self);
.
.
.
end else if compare(class, 'tlistbox')=0 then
begin
cls:=tListBox.Create(self);
.
.
.
end else
.
.
.
class=tedit
width=20
high=12
top=23
left=34
.
.
.
and in you program, you can do as followingif compare(class, 'tedit')=0 then
begin
cls:=TEdit.Create(self);
.
.
.
end else if compare(class, 'tlistbox')=0 then
begin
cls:=tListBox.Create(self);
.
.
.
end else
.
.
.
void CreateYourControl( String ParentFormName , Sting ControlType , String ControlName , String ControlText , x , y , w , h , Style.....)
其实Delphi我是不懂的,不过现在的RAD工具都一个样
void CreateYourControl( String ParentFormName , Sting ControlType , String ControlName , String ControlText , x , y , w , h , Style.....)
其实Delphi我是不懂的,不过现在的RAD工具都一个样
void CreateYourControl( String ParentFormName , Sting ControlType , String ControlName , String ControlText , x , y , w , h , Style.....)
其实Delphi我是不懂的,不过现在的RAD工具都一个样
可以将动态生成的表单以.frm保存成为文件,或以流的方式保存到数据库中,下次启动将保存的表单调用回来即可。
只要你采用写日志的方法将用户本次使用你的系统的有关信息保存到日志里,等下次重新登录时,自动检测日志的信息,初始化你的系统。这样不就行了嘛!
实际上,你自己已经心知肚明了。为什么还要问呢?
Have a good time!
很简单,就是一个动态生成控件以及保存的问题。
delphi怎么保存你设计的结果?它保存在了*.dfm文件里面,看一看dfm文件,就知道该怎么做了。如果觉着那样保存太复杂,用ini文件也是很简单,就象Lionheart写的一样。
procedure TForm1.Save1Click(Sender: TObject);
var
S:TFileStream;
I:Integer;
begin
if SaveDialog1.Execute then
begin
S:=TFileStream.Create(SaveDialog1.FileName,fmOpenWrite or fmCreate);
try
for I:=0 to ControlCount-1 do
if Controls[I].ClassName='TButton' then
S.WriteComponent(Controls[I]);
finally
S.Free;
end;
end;
end;
别忘了加分!
procedure TForm1.Save1Click(Sender: TObject);
var
S:TFileStream;
I:Integer;
begin
if SaveDialog1.Execute then
begin
S:=TFileStream.Create(SaveDialog1.FileName,fmOpenWrite or fmCreate);
try
for I:=0 to ControlCount-1 do
if Controls[I].ClassName='TButton' then
S.WriteComponent(Controls[I]);
finally
S.Free;
end;
end;
end;
读出与前面相反,自已看看吧。别忘了加分!
var
S:TFileStream;
I:Integer;
begin
if SaveDialog1.Execute then
begin
S:=TFileStream.Create(SaveDialog1.FileName,fmOpenWrite or fmCreate);
try
for I:=0 to ControlCount-1 do
if Controls[I].ClassName='TButton' then
S.WriteComponent(Controls[I]);
finally
S.Free;
end;
end;
end;
这是保存,读入方法与之一样,自已看看吧,别忘了加分!
var
S:TFileStream;
I:Integer;
begin
if SaveDialog1.Execute then
begin
S:=TFileStream.Create(SaveDialog1.FileName,fmOpenWrite or fmCreate);
try
for I:=0 to ControlCount-1 do
if Controls[I].ClassName<>'TButton' then
S.WriteComponent(Controls[I]);
finally
S.Free;
end;
end;
end;
这是保存方法,读入与之相似,自已看看吧。别忘了加分!
Delphi中的很多控制都支持SavetoStream和loadFromStream的方法,
不支持的,你可以自己写一对类似的方法,
说白了,就是记录控件重建的必要属性和数据,然后在需要的时候重建它。
把你需要处理的控制都这样封装,
然后你就可以把记录了控件数据的流放到文件中,或者数据库的BLOB字段中。
以后在需要的时候,再恢复。
建议你使用数据库,这样你可以用类型,名称,数据这样的表来管理所有生成的控件。