delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
請各位delphi前輩將如下這段BCB防重開同一窗口的代碼轉成delphi,我試了好久都不成功,對delphi認識太少,多謝了。 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061218170853237.html
//防重開窗口  
  bool   OpenForm(TForm   *WForm)  
    {  
      int   i;  
      bool   FormExist;  
      if   (WForm==NULL)  
            return   false;  
      FormExist=false;  
      for   (i=0;i<Screen->FormCount;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的区别在于不需要通过类实例访问。

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

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

posted on 2009-02-19 16:54 delphi2007 阅读(147) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。