网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.组件开发方式.
.控件移动类的实现之一.
.使用ClientSocket控件实现CSDN论.
.QQ聊天记录器演示程序(二).
.SQLServer中按某字段排列名次.
.用Delphi制作以浏览器为界面的应.
.三层数据库与应用程序服务器的小.
.中国农历算法(delphi).
.远程控制篇:模拟按键.
.(Delphi)如和下载网络文件的例子.
.程序设计和调试中的几点总结.
.三层结构的设计模式.
.让弹出式广告就地正法.
.Delphi报表控件----SReport3强大.
.在Delphi程序中调用控制面板设置.
.字幕图标控件.
.Delphi中动态链接库(DLL)的建立和.
.CRC算法的实现.
.用注册表对delphi程序加密.
.几本我不喜欢的Delphi书籍(之一.

通过字符串,类的引用,创建窗体

发表日期:2006-2-4


//控件单元。

{*
单元说明:     创建模式窗口,和非模式窗口的类,保证非模式窗口只创建一次。
作者        :     笔名:易  一    英文名:yeeyee
E-Mail     :    jane1437@163.com
创建时间:          2005年5月20日
及最后修改时间:
修改人修改时间及:
修改说明:
版权声明:      版权所有,转载请注明本人邮箱和笔名。
*}
unit ShowFormClass;

interface

uses
  SysUtils, Classes,Dialogs, Forms;

type          
  TShowFormClass = class(TComponent)
  private
    { Private declarations }
    //保存要创建的窗体的类名
    FFrmName:string;   
    //判断窗体是否存在。
    function IsFormExist:boolean;
    //得到窗体。
    function GetExistForm:TForm;
    //创建一个类
    function CreateAClass(const AClassName: string): TForm;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); virtual;
    destructor Destroy; override;
   
    //创建并显示窗体。模式窗体。
    procedure ShowModalForm(const AStrForm:string);overload;
    procedure ShowModalForm(AFormClass:TFormClass);overload;
    //创建并显示窗体。非模式窗体。
    procedure ShowModalLessForm(const AStrForm:string);overload;
    procedure ShowModalLessForm(AFormClass:TFormClass);overload;

  published
    { Published declarations }
  end;

procedure Register;

implementation


procedure Register;
begin
  RegisterComponents('Yeeyee', [TShowFormClass]);
end;

constructor TShowFormClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TShowFormClass.Destroy;
begin
  inherited Destroy;
end;

function TShowFormClass.GetExistForm:TForm;
var
  i:integer;
begin
  for i := 0 to (Application.ComponentCount - 1) do
  begin
    if (Application.Components[i] is TForm) then
    begin
      //注意,关键判断这个类型名称是否存在。
      if (application.Components[i] as TForm).ClassType.ClassName = FFrmName then
      begin
        Result:=(application.Components[i] as TForm);
        exit;
      end
    end;
  end;
end;

function TShowFormClass.IsFormExist:boolean;
var
  i:integer;
begin
  Result:=False;
  for i := 0 to (Application.ComponentCount - 1) do
  begin
    if (Application.Components[i] is TForm) then
    begin
      //注意,关键判断这个类型名称是否存在。
      if (application.Components[i] as TForm).ClassType.ClassName = FFrmName then
      begin
        Result:=True;
        exit;
      end
    end;
  end;
end;

//创建一个类
function TShowFormClass.CreateAClass(const AClassName: string): TForm;
var
  LFormClass : TFormClass;
  LForm: TForm;
begin
  LFormClass := TFormClass(FindClass(AClassName));
  LForm := LFormClass.Create(Application);
  Result := LForm;
end;

//创建并显示窗体。模式窗体。传入字符串。
procedure TShowFormClass.ShowModalForm(const AStrForm:string);
var
  LForm: TForm;
begin
  FFrmName:=AStrForm;
  LForm := CreateAClass(FFrmName);
  try
    LForm.ShowModal;
  finally
    LForm.Free;
  end;
end;

//创建并显示窗体。模式窗体。传入类的引用。
procedure TShowFormClass.ShowModalForm(AFormClass:TFormClass);
begin
  with AFormClass.Create(Application) do
  begin
    try
      ShowModal;
    finally
      Free;
    end;
  end;
end;

//创建并显示窗体。模式窗体。传入字符串。
procedure TShowFormClass.ShowModalLessForm(const  AStrForm:string);
var
  LForm: TForm;
begin
  FFrmName:=AStrForm;
  //窗体不存在,则创建。
  if not IsFormExist then
  begin
    LForm := CreateAClass(FFrmName);
    LForm.Show;
  end
  else
  begin
    //存在,则得到窗体。带到最前头。
    LForm:=GetExistForm;
    LForm.BringToFront;
  end;
end;

//创建并显示窗体。模式窗体。传入类的应用。
procedure TShowFormClass.ShowModalLessForm(AFormClass:TFormClass);
var
  LForm: TForm;
begin
  FFrmName:=AFormClass.ClassName;
  //窗体不存在,则创建。
  if not IsFormExist then
  begin
    LForm := CreateAClass(FFrmName);
    LForm.Show;
  end
  else
  begin
    //存在,则得到窗体。带到最前头。
    LForm:=GetExistForm;
    LForm.BringToFront;
  end;
end;

end.

//调用单元

procedure TMainForm.mmiAreaClick(Sender: TObject);
begin
  //
  YShowFormClass.ShowModalForm(TFormArea);
end;

(*

procedure TMainForm.mmiAreaClick(Sender: TObject);
begin
  //
  YShowFormClass.ShowModalForm('TFormArea');
end;

initialization                            
begin
  RegisterClasses([TAboutBox,TFormArea]);
end;

finalization
begin
  UnRegisterClasses([TAboutBox,TFormArea]);
end; *)

上一篇:一个多线程后台扫描的程序和源代码 人气:4524
下一篇:用delphi操作INI文件 人气:5963
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐