Delphi程序员都那里去了?!!!关于句柄/类/类类型的相互转换的高难问题? (100分)

  • 主题发起人 主题发起人 天宇天蓝
  • 开始时间 开始时间

天宇天蓝

Unregistered / Unconfirmed
GUEST, unregistred user!
Function setclassf(hand:thandle):Tclass;<br>var classname:array[0..255]of char;<br>&nbsp; &nbsp; sender:tclass;<br>begin<br>&nbsp; getclassname(hand,classname,255);//返回出句柄的类名<br>&nbsp; sender:=getclass(classname);//返回类名的类型。但为空。不知道什么原因<br>&nbsp; //showmessage(sender.classname);显示sender的类名。<br>&nbsp; result:=sender;<br>end;<br>函数的功能是返回句柄的类型。可是sender总是为空,请为有什么更好的方法?<br>程序的运行流程是:<br>showmessage(setclass(handle).classname);<br>非常感激!!!!!!!<br>
 
procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; WinControl: TWinControl;<br>begin<br>&nbsp; WinControl := FindControl(BitBtn1.Handle);<br>&nbsp; if (WinControl &lt;&gt; nil) then<br>&nbsp; &nbsp; ShowMessage(WinControl.ClassName);<br>end;
 
句柄那里去了?
 
FindControl(Handle: THandle);
 
最关键的你不明白。<br>我是有返回句柄的类的类型。<br>sender:=getclass(classname);//<br>showmessage(sender.classname);只是显示一下serder的类名。<br>我的紧接着就是判断类了。<br>你的能实现吗?
 
If the function succeeds, the return value is the number of characters copied to the specified buffer.<br>它返回的根本不是類名的類型,當然會出錯了.<br>你只能根據註冊了的類型用Classname來找
 
三天后没有更好的答案,我回给你加满分.
 
TClass是没有句柄的<br>TWinControl才开始有句柄<br>函数FindControl根据一个句柄返回它的TWinControl不是一样的吗?<br>为什么一定要通过getclass函数来取得TClass,你可看看Delphi帮助的例子代码,GetClass需要RegisterClasses来注册类后才能使用的<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;{ make sure the classes are registered so that GetClass will work -- }<br>&nbsp; &nbsp;{ Usually, this goes in the initialization section where it is only executed once }<br>&nbsp; RegisterClasses([TIcon, TBitmap, TJPEGImage, TMetafile]);<br>&nbsp; Edit1.Text := GraphicExtension(TGraphicClass(GetClass(Edit2.Text)));<br>&nbsp;end;
 
唉老大,先好好看看帮助。<br>没有注册Class你到哪里找去?<br>改为下面的就行了<br><br>Function setclassf(hand:thandle):Tclass;<br>var classname:array[0..255]of char;<br>&nbsp; &nbsp;sender:tclass;<br>&nbsp; &nbsp;str:string;<br>begin<br>&nbsp;getclassname(hand,@classname,255);//返回出句柄的类名<br>&nbsp;str:=ClassName;<br>&nbsp;RegisterClasses([TForm1]);<br>&nbsp;sender:=getclass(className);//返回类名的类型。但为空。不知道什么原因<br>&nbsp;result:=sender;<br>end;
 
Highpeak的方法肯定是不行的,RegisterClasses([TForm])只是注册了TForm类和它的父类,想TButton肯定没注册,getclass('TButton)也会返回nil的,<br>我觉得你的函数<br>Function setclassf(hand:thandle):Tclass;<br>返回值因为TWinControl,改为<br>Function setclassf(hand:thandle):TWinControl;<br>
 
接受答案了.
 
后退
顶部