请问一下高手: 能不能把一个窗口的名字如:w_Main这个窗口的Name属性值即'w_Main'保存在一定INI文件内,要打开这个窗口时只需从INI文件中调出这个窗口的名字就可以打开这个窗口!简单点来说说是怎么让这个窗口的名称用变量的形式来调用!!请高手给出实例~~~~
请高手帮帮忙!小弟感激不尽!![在线等待]
请高手帮帮忙!小弟感激不尽!![在线等待]
解决方案 »
- 怎样显示图片,用NMFTP控件把图片下载后,怎么把它显示出来
- 关于OnEnter的一点小问题
- 一个lable的后面要紧跟着另一个lable的后面,该怎么做
- 懂ihtmldocument2的高手请进来,up有分
- 200分高送!如何往数据库中读取下列的数据,特别是中间有的数据为空!!
- 怎么点一个button让 outlook express运行?
- Delphi5的水晶报表控件在Delphi6下的安装过程【有兴趣的可以看看】
- 继续请教,关于《实现按 Enter 键后,光标跳到下一控件》Thanks
- 两个listbox同时选中?
- DEIPHI控件求助
- DOS下显示Word?
- 请问如何使sql server 2000 不接受网络连接 ???????????????????
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2); //这个不能省
Application.Run;
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
form_var : TForm;
i : integer;
begin
for i := 0 to Screen.FormCount - 1 do
begin
if Screen.Forms[i].Name = 'Form2' then //Form2你可以从INI读到的String就行了
begin
form_var := Screen.Forms[i];
form_var.ShowModal;
break;
end;
end;
end;end.
如:我现在有一个窗口叫w_Main
我现在把这个窗口的名字保存在了一个INI文件中,
我要怎么才能把从INI文件中读取的这个窗口打开??
通过一个字符串来引用一个变量。比如:
var
varName: String;
OneVar: Integer;
begin
varName := 'OneVar';
//那么现在他想通过varName来引用OneVar这个变量!
end;直接实现这一功能,我目前还没有办法,尽管我曾经非常想实现这个功能!————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
w_Main本身只是一个变量,所以还不如存储它的类名,比如:TForm1。
然后是有办法通过'TForm1'这个字符串来创建它的实例并显示出来的。————————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————————
不过如果你的窗体很多的话,那么动态创建应该是最好的解决方法
forminifile:=tinifile.create(inifilename);
formname:=kminifile.readstring('form','formname','');
if application.FindComponent(formname)=nil then
创建窗体
var ss:string;
begin
ss:=form1.Name;
iniMyFile := TIniFile.Create('e:\1.ini'); //form2保存到ini文件中
iniMyFile.WriteString('x','name', ss);
inimyfile.free;
end;
//form2是activeform,从ini文件中动态创建
procedure TForm1.Button2Click(Sender: TObject);
var
me:string;
name:tform;
begin
iniMyFile := TIniFile.Create('e:\1.ini');
me:=iniMyFile.readstring('x','name','');
name:=tform.create(owner);
name.Name :=me;
name:=tform2.create(owner);
name.Show ;
inimyfile.free;
end;实现不了你杀了我,但是实现了,要给高分,因为试了好久 ^_^