Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1224476
  • 博文数量: 788
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 7005
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-19 15:52
文章存档

2017年(81)

2011年(1)

2009年(369)

2008年(337)

分类:

2009-02-19 17:03:24



//防重開窗口  
  bool   OpenForm(TForm   *WForm)  
    {  
      int   i;  
      bool   FormExist;  
      if   (WForm==NULL)  
            return   false;  
      FormExist=false;  
      for   (i=0;iFormCount;i++)  
          if   (Screen->Forms[i]->ClassType()==WForm->ClassType())  
                {  
                  FormExist=true;  
                  break;  
                }  
      if   (FormExist==false)  
                  return   FormExist;  
      if   (WForm->WindowState==wsMinimized)  
                  ShowWindow(WForm->Handle,SW_SHOWNA);  
      if   (!WForm->Visible)  
                  WForm->Visible=true;  
      WForm->BringToFront()   ;  
      WForm->SetFocus();  
      return   true;  
    }  
 

function   OpenForm(WForm:   TForm):   Boolean;  
  var  
      i:   Integer;  
  begin  
      Result   :=   False;  
      if   WForm   =   nil   then  
          Exit;  
      for   i   :=   0   to   Screen.FormCount   -   1   do  
          if   Screen.Forms[i].ClassType   =   WForm.ClassType   then  
          begin  
              Result   :=   True;  
              Break;  
          end;  
      if   not   Result   then   Exit;  
      if   WForm.WindowState   =   wsMinimized   then  
                  ShowWindow(WForm.Handle,   SW_SHOWNA);  
      if   not   WForm.Visible   then  
                  WForm.Visible   :=   True;  
      WForm.BringToFront;  
      WForm.SetFocus;  
      Result   :=   True;  
  end;  
 

非常感謝,我把這段代碼寫在   private   下,編譯不通過,為什么???

非常感謝,我把這段代碼寫在   private   下,編譯不通過,為什么???  
  =================================================================================  
  要把函数加在TForm1的private,必须改上面代码为  
   
  function   TForm1.OpenForm(WForm:   TForm):   Boolean;

unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  type  
      TForm1   =   class(TForm)  
      private  
          {   Private   declarations   }  
          function   OpenForm(WForm:   TForm):   Boolean;  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
   
  {   TForm1   }  
   
  function   TForm1.OpenForm(WForm:   TForm):   Boolean;  
  var  
      i:   Integer;  
  begin  
      Result   :=   False;  
      if   WForm   =   nil   then  
          Exit;  
      for   i   :=   0   to   Screen.FormCount   -   1   do  
          if   Screen.Forms[i].ClassType   =   WForm.ClassType   then  
          begin  
              Result   :=   True;  
              Break;  
          end;  
      if   not   Result   then   Exit;  
      if   WForm.WindowState   =   wsMinimized   then  
                  ShowWindow(WForm.Handle,   SW_SHOWNA);  
      if   not   WForm.Visible   then  
                  WForm.Visible   :=   True;  
      WForm.BringToFront;  
      WForm.SetFocus;  
      Result   :=   True;  
  end;  
   
  end.  
 

 
  這種情況在函數在delphi里聲明在   private   、public   或   直接和   procedure   寫一起有什么區別??

private私有的,只能类自己或者同单元的其他类使用  
  public公有的,都可。。。  
   
  这种函数直接和procedure写一起,大家都可用,和public的区别在于不需要通过类实例访问。

建议你买或者网上当一本入门书看看。  
 

 
  多謝,結貼。  
  分有點少了,各位大哥笑納。



--------------------------
新闻:专注、极致、快、口碑 互联网创业的葵花宝典
导航:博客园首页  知识库  新闻  招聘  社区  小组  博问  网摘  找找看
阅读(447) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~