delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks

#

我是新手,请问关于建登陆模块的代码问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204220038294.html
假设我在做系统需要"管理员"和"普通用户"登陆,那在表格里我有"userload""password""rights'分别表示"用户名""密码""权限","权限"可以表示"管理员""普通用户",那我想在登陆的时候可以用不同的权限登陆进行操作该怎么写代码?谢谢,新手求助

分开来设计这表吧。  
  用户信息用一张table  
  权限信息又用另一张table  
   
  用ID把他们关联起来,就行.  
   
  至于你上面的.......那你就在登陆时就判断rights值啦,     1是管理员嘛,2是普通工嘛....依次-->

还要代码?  
  case   adoquery.fieldbyname('rights').values   of  
  1:begin  
        //管理员部分代码  
  end;  
  2begin  
        //普通工那部分代码个  
  end;  
  .  
  .  
  end;  
 

用几个全局变量就搞定了

我自己已经解决了.还是谢谢大家

posted @ 2009-04-22 10:43 delphi2007 阅读(149) | 评论 (0)编辑 收藏

Debugger Exception Notification问题?? ?? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204190804295.html
program   Project2;  
   
  {$APPTYPE   CONSOLE}  
   
  uses  
      SysUtils;  
      const  
      filename1='c:\11.txt';  
      filename2='c:\22.txt';  
      var  
      f1,f2:textfile;  
      s:string;  
   
  begin  
  assignfile(f1,filename1);  
  assignfile(f2,filename2);  
  rewrite(f2);  
  writeln(f2,'hello');        
  while   not   Eof(f1)   do  
  begin  
  readln(f1,s);  
  writeln(f2,s);  
  end;  
  closefile(f1);  
  closefile(f2);  
  end.  
   
  调试的时候,老报标题的错误  
  我的qq是44665376  
  哪位高手,能告诉我原因

AssignFile(f1,filename1);  
      FileMode   :=   0;     {Set   file   access   to   read   only   }  
      Reset(f1);  
      ...  
      CloseFile(f1);  
 

posted @ 2009-04-22 10:43 delphi2007 阅读(310) | 评论 (0)编辑 收藏

如何使用overload Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204165744296.html
我在unit1中定义了一个涵数funciton   xxx(cc):double,我想在unti5中重载,请问在unit5中该怎样用呢?还有就是在unit1中是否需在涵数funciton   xxx(cc):double后加上overload?请大家多多帮忙,谢谢?

同一个单元才用overload,多个单元互不相关

那么在同一个单元中又该怎样用呢?  
  是不是:funciton   xxx(cc:integer):double;overload;//已经声名过的.  
  funciton   xxx(cc:double):double;overload;//需要重载的.

观注...

只有一个   不用写overload就可以了

FUNCTION   micUn_GetChecksum(CONST   c_src:   AnsiString;CONST   c_bits:   Byte   =   32):   LongWord;overload;  
  FUNCTION   micUn_GetChecksum(CONST   c_src:   WideString;CONST   c_bits:   Byte   =   32):   LongWord;overload;  
 

摘录DELPHI   HELP   解释得很清楚了  
   
  You   can   declare   more   than   one   routine   in   the   same   scope   with   the   same   name.   This   is   called   overloading.   Overloaded   routines   must   be   declared   with   the   overload   directive   and   must   have   distinguishing   parameter   lists.   For   example,   consider   the   declarations  
   
  function   Divide(X,   Y:   Real):   Real;   overload;  
  begin  
      Result   :=   X/Y;  
  end;  
  function   Divide(X,   Y:   Integer):   Integer;   overload;  
  begin  
      Result   :=   X   div   Y;  
  end;

overload的用法已经有人解释的很清楚了  
  如果在同一个类中,有两个函数或过程,他们的功能很相似,但是需要传入的参数值不同,可以考虑用overload实现,这样在调用的时候,系统会根据传入的参数表自动判断需要调用的是哪个函数。

posted @ 2009-04-22 10:43 delphi2007 阅读(158) | 评论 (0)编辑 收藏

如何实现当有新邮件时主界面及时提醒??----------------在线等! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204162033297.html
当用户A给用户B发送邮件后,用户B的主界面上进行及时提醒??不用time控件间隔从数据库中提取记录.  
  请帮帮小弟吧.

用indy的控件...   看demo

posted @ 2009-04-22 10:43 delphi2007 阅读(254) | 评论 (0)编辑 收藏

新手提问 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204150703298.html
有两个文本文件  
  文件1内容  
  444  
  333  
  222  
  111  
  文件2内容  
  111  
  222  
  我想在文件1中每读出一行再与文件2中的每一行比较,如果相同,就不往下比了,如果读到文件2的最后还是没有相同的,就把文件1的这一行写入文本文件3中,然后再重复,直到文件1读完,我写的代码如下(循环语句部分),调试后没有这个效果,请高人指点、改正,谢谢了  
  While   Not   Eof(F1)   Do  
  begin  
          Readln(F1,Str1);  
          Flage:=true;  
          While   (Not   Eof(F2))   And   Flage=true   Do  
          begin  
                  Readln(F2,Str2);  
                  If   CompareText(str1,str2)=0   Then  
                          begin  
                          Flage:=false;  
                          end;  
          END;  
          If   Flage=true   Then  
                  begin  
                  Writeln(F3,Str1);  
                  end;  
  End;  
 

下面的代码我是用了三个StringList,可以实现你的功能.注意,C:\下要存在1.txt和2.txt,或者你自己改路径也可以.  
   
  var  
      Index1,index2,index3:integer;  
      StrList1,StrList2,StrList3:Tstringlist;  
      found:boolean;  
  begin  
            strlist1:=Tstringlist.Create;  
            strlist2:=Tstringlist.Create;  
            strList3:=TstringList.Create;  
            strlist1.LoadFromFile('c:\1.txt');  
            strlist2.LoadFromFile('c:\2.txt');  
            for   index1:=0   to   strlist1.Count-1   do  
                    begin  
                    for   index2:=0   to   strlist2.Count-1   do  
                            begin  
                            if   strlist2[index2]=strlist1[index1]   then  
                                  begin  
                                  found:=true;  
                                  break;  
                                  end;  
                            end;  
                    if   not   found   then   strlist3.Add(strlist1[index1]);  
                    found:=false;  
                    end;  
            strlist3.SaveToFile('c:\3.txt');  
            strlist3.Free;  
            strlist2.Free;  
            strlist1.Free;  
  end;

忘记在第一个for循环前面给found赋初值了,你自己加上吧:  
  found:=false;  
  或者在第一层for循环开始时赋初值,这样就不需要22行的found:=false了

谢谢lihuasoft的回复,谢谢你给出的代码,我会好好的学习的,如果能指出我的错误,那就太好了,我也就知道自己错在哪里了,这样也是对自己的提高!

以下是你的代码:     注意带注释的那句是我添加的  
   
  While   Not   Eof(F1)   Do  
  begin  
          Readln(F1,Str1);  
          Flage:=true;  
          Reset(F2);//把重置F2的语句reset(f2)放在这里,因为在一次循环之后,游标已到底  
          While   (Not   Eof(F2))   And   Flage=true   Do  
          begin  
                  Readln(F2,Str2);  
                  If   CompareText(str1,str2)=0   Then  
                          begin  
                          Flage:=false;  
                          end;  
          END;  
          If   Flage=true   Then  
                  begin  
                  Writeln(F3,Str1);  
                  end;  
  End;  
  我没有测试,你自己看一下是不是这个原因

太好了,没有错,我调试了,谢谢你lihuasoft老兄,看来我还得好好学习!

posted @ 2009-04-22 10:43 delphi2007 阅读(134) | 评论 (0)编辑 收藏

注册表压缩? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204144814299.html
很多软件都有注册表压缩功能,有没有哪位大侠知道怎么用代码实现注册表的压缩?

我也想知道,好奇中

我也想知道,好奇中  
  ==========================  
   
  好奇害死猫

我是不懂了,看楼下的,注册表的操作倒是看过很多就是没见过压缩的

posted @ 2009-04-22 10:43 delphi2007 阅读(92) | 评论 (0)编辑 收藏

如何设计一个软件的架构,使它可以提供二次开发的功能? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204120343300.html
如题。

哈?这个问题很深奥哦,可以先看看   gof的软件设计模式

posted @ 2009-04-22 10:43 delphi2007 阅读(180) | 评论 (0)编辑 收藏

Hook或者API高手请进-跨进程获取其他程序的DBGrid内容(其它人做的程序) Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061109101554271.html
假设有一个程序A是一个信息管理系统,它的界面上有一个DBGrid;我想写一个程序B来取A程序界面上的DBGrid数据或者DataSource.A程序是别人写的,我没有源码.各位有好的办法吗?

以前有稍微研究过,要看对方是用哪个工具编的,要取的DBGrid在主程序上,还是在Dll上?

我比较关心这个问题,请问这个问题解决了吗?

你可以Hook   TextOutA/TextOutW试试!  
        我可以Hook到用delphi写的!

posted @ 2009-04-08 09:12 delphi2007 阅读(837) | 评论 (0)编辑 收藏

请教如何用delphi程序在windows2003中创建系统帐户 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061109094404272.html
同时定义其所在的组。  
  最好能用delphi   5.0版本实现。  
  谢谢!

看看这样可以吗  
   
  http://linux.softhouse.com.cn/html/200512/2005120610165900012971.html

用命令行

net   user

对不起,太忙,耽误了。

posted @ 2009-04-08 09:12 delphi2007 阅读(207) | 评论 (0)编辑 收藏

时间问题datetimetostr Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108174624273.html
datetimetostr(日期)  
  转换后的函数为2006-11-08   下午   03:02:06  
  我想要的格式为2006-11-08   15:02:06  
  当然不是通过formatdatetime函数  
  为什么我用datetimetostr不能转换为我想要的格式呢。  
  别人机子上都可以的  
 

可能是你机子上的日期格式与别人的不同吧

这样试一下!  
  控制面板----->区域与语言选项---->自定义---->时间标签---->将时间格式中的h变为H即可!

谢谢,问题已经解决

posted @ 2009-04-08 09:12 delphi2007 阅读(384) | 评论 (0)编辑 收藏

怎么样才可以使得窗体中的控件随窗体变化而变化 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108163345274.html
怎么样才可以使得窗体中的控件随窗体变化而变化

设置Align和Anchors属性

在窗体的OnResize事件里重新设置一个目标控件的Left、Top、Width与Height值即可  
 

如果想要控件的位置变而大小不变,可以这样:  
  procedure   TForm1.FormResize(Sender:   TObject);  
  begin  
   
      Button1.Left:=round(left*clientwidth/fwidth);  
      Button1.Top:=round(top*clientheight/fheight);  
   
  end;  
  其中left,top   是最初button1的left与top值,fwidth,fheight是最初form1的width与height值.

posted @ 2009-04-08 09:12 delphi2007 阅读(276) | 评论 (0)编辑 收藏

串口打印问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108153021275.html
串口打印,发什么命令可以改变字体大小  
  如果帮我解决200分相送。

Printer.Canvas.Font.Size:=?  
   
 

我的问题是,直接通过串口写   指令  
  不是用其驱动来打印,如果用Printer,速度会很慢,这个我也会  
  串口指令如:ESC ! n可以直接控制打印机设置字符打印方式  
  等等,我现在的困扰是不知用什么命令可以控制输出的字体的大小

那要看具体打印机型号的  
  看你的打印机说明书

posted @ 2009-04-08 09:12 delphi2007 阅读(226) | 评论 (0)编辑 收藏

求可以对其他程序进行apihook的可用代码!!谢谢 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108152650276.html
求可以对其他程序进行apihook的可用代码!!谢谢

APIHook   示例  
  http://www.delphifans.com/SoftView/SoftView_480.html  
   
  不用   DLL   的   HookAPI   演示  
  http://www.2ccc.com/article.asp?articleid=3763  
   
  RootKit   Hook   API  
  http://www.2ccc.com/article.asp?articleid=3051  
   
   
  盒子中多的是~~~

MadHookCode嘛~  
  很多人用的

请问MadHookCode能够对全局的api进行拦截吗?

MadHookCode在哪里下载呀?

posted @ 2009-04-08 09:12 delphi2007 阅读(205) | 评论 (0)编辑 收藏

除了用一个时间器来定时获得当前时间外。还有什么办法可以实时准确的获得当前时间? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108144052277.html
如题。  
   
  时间器比如设一秒就重新获取一次。可以是可以,但是有没有更好的办法?

date   获得日期,   time   获得时间  
   
  edit1.text:=datetostr(date)+timetostr(time)

你是想获取动态时间吧

用SetTimmer或者timeSetEvent

edit.text   :=   format('yy-mm-dd   hh:nn:ss',now);

好像除了设置定时器外,就没有其他方法能获取了。  
  获取时间的方法有很多中。最精确的是微软提供的多媒体库中获取时间的函数,具体忘了。你查下微软资料。

还有一个办法就是在访问“标准时网站”得到当前标准时间

edit.text   :=   format('yy-mm-dd   hh:nn:ss',now);     出错

FormatDateTime

posted @ 2009-04-08 09:12 delphi2007 阅读(302) | 评论 (0)编辑 收藏

程序关闭后会自动清楚所有的变量吗? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108134739278.html
我的一个程序,里面有窗口句柄变量、进程句柄变量等等很多!  
  如果程序中没有释放这些变量。关闭程序后,这些都会释放吗?  
   
  还有我程序中使用的键盘钩子,如果不释放键盘钩子,程序关闭后会自己卸载吗?

会的肯定会的

这些都属于进程内资源,肯定会释放的,但如果申请了系统资源,如共享内存等,是不会自动释放的.还是要手工释放,

肯定会释放的,但如果申请了系统资源,如共享内存等,是不会自动释放的.还是要手工释放

键盘钩子   可能不会自己卸载

会释放的

会的

posted @ 2009-04-08 09:12 delphi2007 阅读(154) | 评论 (0)编辑 收藏

关于 打印设置 的问题 讨论。 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108134026279.html
打印的很多选项设置,打印到哪台打印机,打印的份数,打印方向,纸张类型等。  
  究竟该如何设置?  
   
  比如   打印的份数  
  printer.Copies:=3;  
  是否这样设置就行了?  
  我看DELPHI5开发人员指南上的例子,是通过设置T   D   e   v   i   c   e   M   o   d   e结构来做的。  
   
  对这个问题,打印的份数,我实际测试了一下,还必须采用   设置T   D   e   v   i   c   e   M   o   d   e结构的方法,仅用这句printer.Copies:=3;只打印一份。  
   
  但是对   打印方向,我用下面这句就行了。  
  printer.Orientation:=poLandscape;  
   
  我想请教各位朋友,设置打印选项,究竟该如何进行?我看到很多例子都是   设置T   D   e   v   i   c   e   M   o   d   e结构。那么printer.后面的很多打印选项属性是做什么用的。  
  ---------------------------  
  10.6.2   设置打印份数  
  可以通过设置T   D   e   v   i   c   e   M   o   d   e结构中的d   m   C   o   p   i   e   s字段来告诉打印机要打印的份数。下面的代码演示  
  了这一点:  
   
  With   DevMode^   do    
   
  b   e   g   i   n    
   
  dmFields:=dmFields   or   DM_COPIES;    
   
  d   m   C   o   p   i   e   s   :   =   C   o   p   i   e   s   ;    
   
  e   n   d   ;    
   
   
  望大家指教。  
 

顶   我用C#   写过delphi没写过这方面的

posted @ 2009-04-08 09:12 delphi2007 阅读(202) | 评论 (0)编辑 收藏

关于判断文件唯一性,怎么提取特征码 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108132642280.html
困惑,用什么来判断文件的唯一性,用findwindow判断程序,误报可能太大,有哪位大大能提供delphi的判断文件的特征码的好例子,麻烦写出来,指点一二。分不多,因为不会的东西太多了,留着以后学习。  
 

判断文件唯一性还是窗口唯一性,findwindow是查找窗口用的。

是判断文件的唯一性,以前都是用findwindow()查出运行着的文件名,然后根据这个判断文件是否存在,但同类或是同名窗口的程序太多,容易误查,就是这个意思,不知道你老鸟们能不能听的懂。

如果事先知道   文件的大小,就可以利用这一点

主要是想查殺他,知道大小沒什麼用處,如果對方加殼或是做了數據壓縮,那麼知道大小就沒什麼作用了。

读取文件的md5特征码试试

是想查殺一個程序,MD5碼好象不行,MD5碼是保證文件的正確性,说明是你发布的原創,沒被別人修改過。

继续等待高手的解答。

什么是特征码  
  程序运行时,在内存中为完成特定的动作,要有特殊的指令,  
  一个程序在运行时,同一内存地址的指令是相同的  
  同一个程序中,一段连续的地址(它的指令相同),截取这段地址   这就是特征码  
   
  特征码怎么提取  
  对程序进行脱壳   反汇编   提取一段连续的地址(它的指令相同)即可  
   
  因为楼主所以知道了什么事特征码  
 

有具体的例子吗?我对汇编不是太了解。最好不要是汇编的

頂到高手來為止

那你还是算了吧。如果happyggy说的这么清楚你都不知道的话,那就不要用特征码来做你想做的事了。

就是不懂才問,如果懂,我還用的著問嗎?提取特征碼又不是只匯編才能做的到的。

特征码也是杀毒软件主观制定的,自己用的话,爱取哪一段就取哪一段呗

有没有大大给个例子提示下

分不够还可以加

顶上有大大来帮助为止

http://www.delphibox.com/article.asp?articleid=2576

感谢,但你给我的是内存读取相关的例子,暂时用不上

继续顶,顶到高人到来

posted @ 2009-04-08 09:12 delphi2007 阅读(511) | 评论 (0)编辑 收藏

知道窗口句柄如何知道文件名? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108114249281.html
知道窗口句柄,怎么得到该程序的文件名???

先通过GetWindowThreadProcessId取得窗口所属进程的PID,再通过枚举系统进程,得到该进程的文件名。枚举进程可以通过系统快照:CreateToolhelp32Snapshot,   Process32First,   Process32Next等API来进行。

详细点啊

uses   tlhelp32;  
   
  function   CrnGetExeFileFromWindow(hWin:   HWND):   string;  
  var  
          dwPID:   DWORD;  
          strExePath:   String;  
          pToolhelp:   THandle;  
          pe:   TProcessEntry32;  
          me:   TModuleEntry32;  
          bOK:   bool;  
  begin  
          GetWindowThreadProcessId(hWin,   @dwPID);  
          //   建立系统快照  
          pToolhelp   :=   CreateToolhelp32Snapshot(TH32CS_SNAPALL,   dwPID);  
          //   获取可执行文件的路径  
          if   Win32Platform   <>   VER_PLATFORM_WIN32_NT   then   //   Win9x  
          begin  
                  ZeroMemory(@pe,   SizeOf(pe));  
                  pe.dwSize   :=   SizeOf(pe);  
                  bOK   :=   Process32First(pToolhelp,   pe);  
                  while(bOK)   do  
                  begin  
                          if   pe.th32ProcessID   =   dwPID   then  
                          begin  
                                  strExePath   :=   pe.szExeFile;  
                                  break;  
                          end;  
                          bOK   :=   Process32Next(pToolhelp,   pe);  
                  end;  
          end  
          else   //   WinNT  
          begin  
                  ZeroMemory(@me,   SizeOf(me));  
                  me.dwSize   :=   SizeOf(me);  
                  Module32First(pToolhelp,   me);  
                  strExePath   :=   me.szExePath;  
          end;  
          CloseHandle(pToolhelp);  
          Result   :=   strExePath;  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
          hWin:   THandle;  
  begin  
          //   这里替换成你要查询的窗口句柄就可以了,我随便指定了一个值。  
          hWin   :=   THandle($008C0302);    
          ShowMessage(CrnGetExeFileFromWindow(hWin));  
  end;

谢谢

posted @ 2009-04-08 09:12 delphi2007 阅读(325) | 评论 (0)编辑 收藏

如何不通这注册表取双网卡所对应的子网? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061108110332282.html
如题  
  谢谢

ipconfig   -all  
  api要查下....  
 

posted @ 2009-04-08 09:12 delphi2007 阅读(158) | 评论 (0)编辑 收藏

这个不对了,找不到控件 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107194340283.html
在窗体中放了一个edit   和一个按钮。  
  用file-new-other里的thread   object   创建了一个新线程类(Tmy)。  
  里面写了这句代码:  
  procedure   Tmy.Execute;  
  begin  
      {   Place   thread   code   here   }  
        form1.edit.text:='ddd';     //就是这句  
   
  end;  
  这是编译时的错误  
      [Error]   Unit2.pas(35):   Undeclared   identifier:   'form1'  
      [Error]   Unit2.pas(35):   Missing   operator   or   semicolon  
      [Error]   Unit2.pas(35):   Statement   expected,   but   expression   of   type   'String'   found  
      [Fatal   Error]   Unit1.pas(7):   Could   not   compile   used   unit   'Unit2.pas'  
   
  我在Unit1中包含了unit2,  
   
  是什么原因呢??

自己解决了。

posted @ 2009-04-08 09:12 delphi2007 阅读(179) | 评论 (0)编辑 收藏

为什么WaitForMultipleObjects返回后,对应的handle仍处于激发状态? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107172543284.html
我写了个用WaitForMultipleObjects同步线程的例子,窗体上有三个memo,有一个mutex数组变量,分别对应一个memo,主线程里创建调度线程,在调度线程里通过WaitForMultipleObjects得到当前空闲的mutex,对应的我就知道了哪个memo是空闲的,然后创建一个工作线程,工作线程里向对应的memo写数据,  
  现在的问题是,WaitForMultipleObjects返回后,始终得到的是0,按理WaitForMultipleObjects返回后,mutex数组的第一个元素就处于未激发状态了,如果再调用WaitForMultipleObjects就不应返回0了  
  。  
  下面是代码,请帮我看看问题在哪  
   
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          Button1:   TButton;  
          Memo1:   TMemo;  
          Memo2:   TMemo;  
          Memo3:   TMemo;  
          procedure   FormCreate(Sender:   TObject);  
          procedure   FormDestroy(Sender:   TObject);  
          procedure   Button1Click(Sender:   TObject);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
      TDispThd   =   class(TThread)  
      private  
   
      protected  
          procedure   Execute;   override;  
      public  
          constructor   Create(Mone:   TMemo;   Mtwo:   TMemo;   Mthree:   TMemo);  
      end;  
      TWorker   =   class(TThread)  
      private  
          FMemo:   TMemo;  
          FTID:   integer;  
          FIndex:   integer;  
      protected  
          procedure   Execute;   override;  
          procedure   UpdateMemo;  
      public  
          constructor   Create(index,   id:   integer;   memo:   TMemo);  
      end;  
   
  var  
      Form1:   TForm1;  
      ConnMutexUse:   array[0..2]   of   THandle;  
      MemoArr:   array[0..2]   of   TMemo;  
   
  procedure   GetIdleMemo(var   id:   integer);  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   GetIdleMemo(var   id:   integer);  
  var  
      WaitRes:   integer;  
  begin  
      WaitRes   :=   WaitForMultipleObjects(3,   @ConnMutexUse,   False,   INFINITE);  
      id   :=   WaitRes   -   WAIT_OBJECT_0;  
    //   waitres   :=   WaitForSingleObject(ConnMutexUse[ID],   10);  
    //   if   waitres   =   WAIT_OBJECT_0   then  
    //       raise   Exception.Create('bad,i   catch   it');  
      if   (id   <   0)   or   (id   >   2)   then  
          raise   Exception.Create('GetIdle错误');  
  end;  
   
  constructor   TDispThd.Create(Mone:   TMemo;   Mtwo:   TMemo;   Mthree:   TMemo);  
  begin  
      MemoArr[0]   :=   Mone;  
      MemoArr[1]   :=   Mtwo;  
      MemoArr[2]   :=   Mthree;  
      inherited   Create(false);  
  end;  
   
  procedure   TDispThd.Execute;  
  var  
      id,   i,   WaitRes:   integer;  
  begin  
      FreeOnTerminate   :=   true;  
      i   :=   0;  
      while   true   do  
      begin  
          GetIdleMemo(id);  
      //     WaitRes   :=   WaitForMultipleObjects(3,   @ConnMutexUse,   False,   INFINITE);  
      //     id   :=   WaitRes   -   WAIT_OBJECT_0;  
      //     waitres   :=   WaitForSingleObject(ConnMutexUse[ID],   10);  
      //     if   waitres   =   WAIT_OBJECT_0   then  
      //         raise   Exception.Create('bad,i   catch   it');  
      //     if   (id   <   0)   or   (id   >   2)   then  
      //         raise   Exception.Create('GetIdle错误');  
   
          TWorker.Create(i,   id,   MemoArr[id]);  
          sleep(2000);  
          Inc(i);  
      end;  
  end;  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
  var  
      i:   integer;  
  begin  
      for   i   :=   0   to   2   do  
          ConnMutexUse[i]   :=   CreateMutex(nil,   false,   nil);  
  end;  
   
  procedure   TForm1.FormDestroy(Sender:   TObject);  
  var  
      i:   integer;  
  begin  
      for   i   :=   0   to   2   do  
          CloseHandle(ConnMutexUse[i]);  
  end;  
   
  constructor   TWorker.Create(index,   id:   integer;   memo:   TMemo);  
  begin  
      FMemo   :=   memo;  
      FTID   :=   id;  
      FIndex   :=   index;  
      FreeOnTerminate   :=   true;  
      inherited   Create(false);  
  end;  
   
  procedure   TWorker.Execute;  
  var  
      waitres:   integer;  
  begin  
      try  
          Synchronize(UpdateMemo);  
  //         waitres   :=   WaitForSingleObject(ConnMutexUse[FTID],   10);  
  //         if   waitres   =   WAIT_OBJECT_0   then  
  //             raise   Exception.Create('bad,i   catch   it');  
          Sleep(50000);  
      finally  
          ReleaseMutex(ConnMutexUse[FTID]);  
      end;  
  end;  
   
  procedure   TWorker.UpdateMemo;  
  begin  
      FMemo.Lines.Add(IntToStr(FTID)   +   ':'   +   IntToStr(FIndex));  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      TDispThd.Create(memo1,   Memo2,   Memo3);  
  end;  
   
  end.  
 

帮你顶

拥有mutex的线程是不会被锁定的,可以一直重入,它只会锁定其他线程。  
  通过WaitForSingleObject递增mutex内部计数,ReleaseMutex递减mutex内部计数。  
 

楼上正解~~~~  
   
  因为LZ的GetIdleMemo函数一直是由线程TDispThd来调用的,所以一直都可重入WaitForMultiOjbect,将GetIdleMemo这个函数放在TWorker.Execute执行,即可;  
   
  如下所示,我改了一下代码,是可以的.  
   
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          Memo1:   TMemo;  
          Memo2:   TMemo;  
          Memo3:   TMemo;  
          Button1:   TButton;  
          procedure   FormCreate(Sender:   TObject);  
          procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
          procedure   Button1Click(Sender:   TObject);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
      TDispThd   =   class(TThread)  
      private  
          ConnMutexUse:   array[0..2]   of   THandle;  
      protected  
          procedure   Execute;   override;  
      public  
   
          constructor   Create(Mone:   TMemo;   Mtwo:   TMemo;   Mthree:   TMemo);  
      end;  
   
      TWorker   =   class(TThread)  
      private  
          FMemo:   TMemo;  
          FTID:   integer;  
          FIndex:   integer;  
   
      protected  
          procedure   Execute;   override;  
          procedure   UpdateMemo;  
      public  
          constructor   Create(index,   id:   integer;   memo:   TMemo);overload;  
          constructor   Create(index:   integer);   overload;  
      end;  
  var  
      Form1:   TForm1;  
      ConnMutexUse:   array[0..2]   of   THandle;  
      MemoArr:   array[0..2]   of   TMemo;  
   
      procedure   GetIdleMemo(var   id:   integer);  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   GetIdleMemo(var   id:   integer);  
  var  
      WaitRes:   integer;  
  begin  
      WaitRes   :=   WaitForMultipleObjects(3,   @ConnMutexUse,   FALSE,   INFINITE);  
      id   :=   WaitRes   -   WAIT_OBJECT_0;  
   
      if   (id   <   0)   or   (id   >   2)   then  
          raise   Exception.Create('GetIdle错误');  
  end;  
   
  {   TWorker   }  
   
  constructor   TWorker.Create(index,   id:   integer;   memo:   TMemo);  
  begin  
      FMemo   :=   memo;  
      FTID   :=   id;  
      FIndex   :=   index;  
      FreeOnTerminate   :=   true;  
      inherited   Create(false);  
  end;  
   
  constructor   TWorker.Create(index:   integer);   //增加一个构造函数  
  begin  
      FIndex   :=   index;  
      FreeOnTerminate   :=   true;  
      inherited   Create(false);  
  end;  
   
  procedure   TWorker.Execute;  
  var  
      waitres:   integer;  
  begin  
      GetIdleMemo(FTID);  
      FMemo   :=   MemoArr[FTID];  
      try  
          Synchronize(UpdateMemo);  
          Sleep(3500);   //时间调短,大于3*1000即可  
      finally  
          ReleaseMutex(ConnMutexUse[FTID]);  
      end;  
   
  end;  
   
  procedure   TWorker.UpdateMemo;  
  begin  
      FMemo.Lines.Add(IntToStr(FTID)   +   ':'   +   IntToStr(FIndex));  
  end;  
   
  {   TDispThd   }  
   
  constructor   TDispThd.Create(Mone,   Mtwo,   Mthree:   TMemo);  
  begin  
      MemoArr[0]   :=   Mone;  
      MemoArr[1]   :=   Mtwo;  
      MemoArr[2]   :=   Mthree;  
      inherited   Create(false);  
  end;  
   
  procedure   TDispThd.Execute;  
  var  
      id,   i,   WaitRes:   integer;  
  begin  
      FreeOnTerminate   :=   true;  
      i   :=   0;  
   
   
      while   true   do  
      begin  
          //GetIdleMemo(id);  
          //TWorker.Create(i,   id,   MemoArr[id]);  
           
          TWorker.Create(i);  
          sleep(1000);   //时间调短  
          Inc(i);  
      end;  
   
  end;  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
   
  var  
      i:   integer;  
  begin  
      for   i   :=   0   to   2   do  
          ConnMutexUse[i]   :=   CreateMutex(nil,   FALSE,   nil);  
  end;  
   
  procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  var  
      i:   integer;  
  begin  
      for   i   :=   0   to   2   do  
          CloseHandle(ConnMutexUse[i]);  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      TDispThd.Create(memo1,   Memo2,   Memo3);  
  end;  
   
  end.

谢谢各位的帮助

posted @ 2009-04-08 09:12 delphi2007 阅读(512) | 评论 (0)编辑 收藏

waitforsingleobject的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107162800285.html
我在主线程中用了waitforsingleobject,可以用吗,如果可以的话,在线程中调用这个函数的的话还用不用Synchronize函数啊

1.主线程等待子线程,不必用waitforsingleobject,  
  这样就可以了:   thread.WaitFor;  
   
  2.Synchronize函数,是在子线程中使用,通知主线程来执行Synchronize参数指定中的函数;  
   
  Synchronize指定的函数,通常用于更新一些界面上的显示,这些工作放在子线程中处理,是不好的.

posted @ 2009-04-08 09:12 delphi2007 阅读(255) | 评论 (0)编辑 收藏

如何關閉正在運行的特定的程式?急! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107161535286.html
如何關閉正在運行的特定的程式?急!,   小弟謝謝先!
posted @ 2009-04-08 09:12 delphi2007 阅读(162) | 评论 (0)编辑 收藏

多线程的sleep和suspend问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107160754287.html
procedure   TAthread.Execute;  
  begin  
            while   not   Terminated   do  
            begin  
                      try  
                          //处理函数  
                      finally  
                          sleep(20);  
                          self.Suspend;  
                      end;  
            end;  
  end;  
  请问大家,sleep和suspend有什么区别,具体用法是什么啊,还有用了sleep还能用suspend吗,sleep里的时间是多少,怎么确定啊,在线程的处理函数里我还用到了idudpserver发送数据,用控制同步吗

呵呵,我来说一下~~~  
   
  ...  
  sleep(20);//让线程暂停20毫秒,再运行下一条语句  
  self.Suspend;//让线程暂停,不再运行下边代码  
  ...  
   
  看得出来了吧.  
   
  sleep是仅仅暂停一下,然后接着运行~~~  
   
  而Suspend把线程自己停下来,不在运行了,如果想要继续运行,必须在主线程或者其它纯种中,  
  调用   线程.resume();   来恢复运行;  
   
 

>>sleep里的时间是多少,怎么确定啊  
   
  sleep的参数是以   毫秒为单位;     sleep(1000);//即sleep   1秒;  
   
  >>在线程的处理函数里我还用到了idudpserver发送数据,用控制同步吗  
   
  同步与否,跟写在线程的execute中,和写在线程外面没有什么关系,是你的实现业务需求来确定的.  
   
  而且,你说的同步?还不太明白,请你说清晰一些你的情况;  
 

我记的看过一篇文章说线程的sleep是让出cpu的时间片,而线程中必须要写上sleep的,不然会一直占用cpu,程序运行会卡住,所以我想问有下,sleep要让出多少才合理

上面已经说得很清楚,合不合理,看你自己的意愿.要看你程序的具体要求,如果你要深究的话,最后看一下这方面的资料,关于cpu的时间片,通常是sleep(50-100)不等.

posted @ 2009-04-08 09:12 delphi2007 阅读(507) | 评论 (0)编辑 收藏

关于playsound()的问题,在线等 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107145536288.html
uses   MMSystem;  
  sndPlaysound(PChar('alarm.wav'),SND_LOOP);  
  怎么声音不循环播放呢?奇怪

没人知道啊???

看看sndPlaysound这个函数的帮助

帮助就这么写的,用SND_LOOP可以循环  
 

sndPlaysound(PChar('alarm.wav'),SND_ASYNC   or   SND_LOOP);

多谢楼上朋友

posted @ 2009-04-08 09:12 delphi2007 阅读(161) | 评论 (0)编辑 收藏

delphi有几种方法创建子线程 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107143711289.html
delphi有几种方法创建子线程

createthead

posted @ 2009-04-08 09:12 delphi2007 阅读(321) | 评论 (0)编辑 收藏

关于文件复制与删除的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061107120249290.html
想编个程序,把机器上所有的文件名为A.EXE的文件删除,再把文件B.EXE从机器的X文件夹下拷贝到机器上所有名称为Y的文件夹下,请问如何编写程序?

FindFirst()  
  FindNext()  
  DeleteFile()  
  CopyFile()  
  这几个api就够用了吧

楼上是一种方法  
  WINEXEC()+DOS命令也可

posted @ 2009-04-08 09:12 delphi2007 阅读(129) | 评论 (0)编辑 收藏

开机先出先自己的程序界面,输入用户名和口令后再进入windows Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061106222842291.html
我想实现这样一个功能,开机先出先自己的程序界面,输入用户名和口令后再进入windows(winxp或者win2000),有点类似网吧里面的登陆模式,请问大家如何实现这个功能?欢迎给出思路或者代码。急用,在线等,谢谢!!!

补充说明:开机先出先自己的程序界面,输入的用户名和口令是程序用到的用户名和口令,和windows的用户名和口令不是一回事

http://windowssdk.msdn.microsoft.com/en-us/library/aa378326.aspx

顶蒋老大~

posted @ 2009-04-08 09:12 delphi2007 阅读(188) | 评论 (0)编辑 收藏

如何快速的从几千个文件中删除你想要删除的文件??关键是算法!! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061106211720292.html
如何快速的从几千个文件中删除你想要删除的文件?这些文件是我按照时间记录的,比如:20061106101010.txt,20061106121212.txt.....,然后,我要按照FiFo的原则将老的文件删除,  
  哪位老兄有好办法!!  
 

你可以记录在文件存放时,就用一个数组进行记录,然后进行FIFO原则进行删除,不知道这样满足你的要求不.

posted @ 2009-04-08 09:12 delphi2007 阅读(135) | 评论 (0)编辑 收藏

关于调用windows内核问题×××××××××××× Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061106205556293.html
上网看过一些windows内核调用的文章  
  我想用rundll32   user,wnetconnectdialog打开"映射网络驱动器"窗口  
              rundll32   user,repaintscreen         刷新桌面  
   
  但是系统有错误提示说,“加载user时出错   找不到指定模块”  
   
  然后我就把整篇文章的命令都尝试过,"rundll32   keyboard,disable"   -   锁写键盘     以及     "rundll32   mouse,disable"   -   让鼠标失效,都会出现相关错误:“加载keyboard时出错   找不到指定模块”以及“加载mouse时出错   找不到指定模块”。  
   
  但是"rundll32   shell32,Control_RunDLL"   -   运行控制面板   能正常运行。  
   
  那么请问为什么shell32能正常加载,而user/keyboard/mouse却加载出错呢?

user.dll,keyboard.dll,mouse.dll都是win98中的,win2k/xp没有这几个DLL了,你看的文章太老了

找了个win98试了一下,的确98下可用

呵呵,看来文章真的老啦,那么请问NT系统是用什么命令来调用这些win内核呢?

mark

一般api     delphi都封装好了..  
  另外可以去jedi下   其他单元  
 

用delphi调用它更方便些,我试了一下,有些函数用rundll32是无法运行的

这个都叫内核调用?!汗~

自定义   相对   概念..

posted @ 2009-04-08 09:12 delphi2007 阅读(153) | 评论 (0)编辑 收藏

仅列出标题
共34页: First 3 4 5 6 7 8 9 10 11 Last