两个api函数GetDlgltem,GetDlgltemText delphi中声明出错,是不是需要在user单元加什么。另:取一个字符串的第N位,N个字符的函

  • 主题发起人 主题发起人 路远
  • 开始时间 开始时间

路远

Unregistered / Unconfirmed
GUEST, unregistred user!
两个api函数GetDlgltem,GetDlgltemText delphi中声明出错,是不是需要在user单元加什么。另:取一个字符串的第N位,N个字符的函数是什么。(100分)<br />有两个api函数GetDlgltem,GetDlgltemText。我声明后也不能运行.<br><br>我这样声明 function &nbsp;GetDlgltem (hDlg:Thandle;nlDDlgltem :integer ): THandle;<br>原型 HWND GetDlgltem(HWND hDlg,int nlDDlgltem);<br>结果出错提示:[Error] Unit1.pas(26): Unsatisfied forward or external declaration: 'GetDlgltem'<br>2.apiGetDlgltemText .<br>我在程序里声明function apiGetDlgltemText (hDlg:THandle;nlDDlltem:integer;DlgltemText:String; nMazCount:integer):pchar;//<br>返回值:如果函数调用成功,则返回值表示被复制缓冲区的字符串的长度,不包括以NULL结尾的字符串。如果函数调用失败,则返回值为零。<br>原型:UINT GetDlgltemText(HWND hDlg,int nlDDlltem,LPTSTR IpString int nMazCount);<br>出错提示[Error] Unit1.pas(26): Unsatisfied forward or external declaration: 'apiGetDlgltemText'<br>另:取一个字符串的第N位,N个字符的函数是什么。<br>声明位置:<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br><br>&nbsp; &nbsp; function &nbsp;GetDlgltem (hDlg:Thandle;nlDDlgltem :integer ): THandle;<br>&nbsp; &nbsp; function &nbsp;GetDlgltemText (hDlg:THandle;nlDDlltem:integer;DlgltemText:String; nMazCount:integer):Char;<br><br><br><br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br><br>&nbsp; end;<br>&nbsp; <br>&nbsp;
 
字符串是 str, 第n个字符是str[n]
 
要是取字符串从第2位开始的三个字符呢?
 
找本书看看吧,<br>partStr := copy(str,2,4);
 
加ShellApi了?
 
copy(str,2,3)
 
你声明的地方错了吧:)<br>你好像是声明了一个TForm1类的published成员函数,又没有它的实现代码,所以出错~<br>你要用的两个函数在windows单元都有声明,你可以直接使用,至于声明的方法,你可以看看windows单元是怎么做的~
 
加ShellApi不行,<br>还是提示<br>[Error] Unit2.pas(54): Undeclared identifier: 'GetDlgltem'<br>[Error] Unit2.pas(55): Undeclared identifier: 'GetDlgltemText'<br>&nbsp;。能不能自己定义一下函数。 <br>&nbsp;我的语句时这样的<br>&nbsp; if ClassName = 'Static' then<br>&nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Setlength(DlgltemText,100);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlDDlgltem := GetWindowLong (foundwnd,GWL_ID);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HINSTANCE := GetDlgltem (foundwnd, nlDDlgltem);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetDlgltemText(HINSTANCE,nlDDlgltem,DlgltemText,100);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partStr := copy(DlgltemText,2,2) ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if partStr= ':/' &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;如果我把它们分开 在begin 前<br>&nbsp; &nbsp; &nbsp;这样定义一下function &nbsp;GetDlgltem (hwnd:Thandle;nlDDlgltem :integer ): THandle;Stdcall ;到还可以,不过下一个函数 就不能用了。<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp;我这两个函数定义成重载函数,<br>&nbsp; &nbsp; &nbsp;function &nbsp;GetDlgltem (hDlg:Thandle;nlDDlgltem :integer): THandle;overload;<br>function &nbsp;GetDlgltem (hDlg:THandle;nlDDlgltem :integer;DlgltemText:String; nMazCount:integer):string; overload ;<br>也行不通, 提示[Error] Unit2.pas(69): There is no overloaded version of 'GetDlgltem' that can be called with these arguments<br>&nbsp;api函数能不能在全局部分声明。什么时候调用的时候在调用。<br>我试了在下面部分声明<br>type<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br><br>&nbsp; &nbsp;{ Public declarations }<br>&nbsp; end;<br><br>var<br>大家看往哪儿声明好呢?<br>windows单元是不是,windows.pas文件呀,我找啦,没有我搜索了delphi下RTL目录,没有这两个函数
 
晕~<br>千万不要这样声明:<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br><br>&nbsp; &nbsp; function &nbsp;GetDlgltem (hDlg:Thandle;nlDDlgltem :integer ): THandle;<br>&nbsp; &nbsp; function &nbsp;GetDlgltemText (hDlg:THandle;nlDDlltem:integer;DlgltemText:String; nMazCount:integer):Char;<br>这是给TForm1加一个成员函数!<br>在windows单元有这个函数,只是你把函数名写错了GetDlgItem不是GetDlgltem,记住是I不是l!<br>如果你一定要自己声明,在implementation的前面或者后面直接这样声明:<br>&nbsp; function GetDlgItem(hDlg: HWND; nIDDlgItem: Integer): HWND; stdcall; external user32 name 'GetDlgItem';
 
多人接受答案了。
 
后退
顶部