各位高手,最近可用分没见长大家不要闲小弟吝啬啊!下面是我在Delphi编程技术内幕一书中遇到的一段代码,有些地方看不大明白,请高人指点!
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    UseThread: TButton;
    NoThread: TButton;
    procedure UseThreadClick(Sender: TObject);
    procedure NoThreadClick(Sender: TObject);  end;var
  Form1: TForm1;implementation{$R *.dfm}
function ThreadFunc(p:Pointer):Longint;stdcall; //这里的函数没有声明,
                                               //为什么声明了反而出错
var
  i:integer;
  DC:HDC;//这个变量是干什么用的?
  s:string;
begin
  DC:= GetDC(Form1.Handle);//这里又是什么意思?
  for i:=0 to 1000000 do
  begin
    s:=inttostr(i);
    TextOut(DC,10,10,Pchar(s),Length(s));//看F1帮助TextOut里面好像不是这样用的(里面的参数没有DC啊!)
  end;
  releaseDC(Form1.Handle,DC);
end;
procedure TForm1.UseThreadClick(Sender: TObject);
var
  hThread:THandle;
  ThreadID:DWord;
begin
  hThread:=CreateThread(nil,0,@ThreadFunc,nil,0,threadID);
  if hthread = 0 then
    MessageBox(Handle,'no thread',nil,MB_OK);
end;procedure TForm1.NoThreadClick(Sender: TObject);
begin
 ThreadFunc(nil);//这里又是什么意思呢?是不是将ThreadFunc的内存分配指针为空,这样调用ThreadFunc就没有创建线程?
end;end.

解决方案 »

  1.   

    1.function ThreadFunc(p:Pointer):Longint;stdcall;
    老大,你没看清楚吧?stdcall,还要怎么声明啊?
    2.HDC = type LongWord
    The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window. The display device context can be used in subsequent GDI functions to draw in the client area of the window. This function retrieves a common, class, or private device context depending on the class style specified for the specified window. For common device contexts, GetDC assigns default attributes to the device context each time it is retrieved. For class and private device contexts, GetDC leaves the previously assigned attributes unchanged. 
    3。BOOL TextOut(    HDC hdc, // handle of device context 
        int nXStart, // x-coordinate of starting position  
        int nYStart, // y-coordinate of starting position  
        LPCTSTR lpString, // address of string 
        int cbString  // number of characters in string 
       );第一个参数就是,你怎么看的帮助啊??
    4  ThreadFunc写的好像有问题啊!楼主你保证没写错嘛?传入参数q根本没用到啊?
      

  2.   

    楼上的 我得帮助怎么找不到啊!我的帮助是这样的◎Delphi syntax:procedure TextOut(X, Y: Integer; const Text: string);C++ syntax:void __fastcall TextOut(int X, int Y, const AnsiString Text);DescriptionUse TextOut to write a string onto the canvas. The string will be written using the current value of Font. Use the TextExtent method to determine the space occupied by the text in the image. To write only the text that fits within a clipping rectangle, use TextRect instead.After a call to TextOut, the PenPos property indicates the point at the top right of the text on the canvas.
      

  3.   

    implementation
    //在这里申明的函数是全局的。也就是说。这个函数是在这里被申明的。
    ..
    function ThreadFunc(p:Pointer):Longint;stdcall; //这里的函数没有声明,
                                                   //为什么声明了反而出错DC:HDC;//这个变量是干什么用的?
    //////
    用过C++你就知道这个是什么东西了。“设备描述符”,比如一个绘画场景的HANDLE。CANVAS.Handle........
    ///////////
    DC:= GetDC(Form1.Handle);//这里又是什么意思?
    可以猜到接下来的代码里应该是要在FORM上绘画。。
    /////
    TextOut(DC,10,10,Pchar(s),Length(s));//看F1帮助TextOut里面好像不是这样用的(里面的参数没有DC啊!)
    你知道有CANVAS。TEXTOUT();这个方法的本质就是这个API。textout;你可以去看SDK HELP里它的说明。//////////
    ThreadFunc(nil);//这里又是什么意思呢?
    这里我看不懂,这个函数不全,没有返回值,没有看到参数的使用情况,猜不到想干什么。
      

  4.   

    非常感谢你们两位!大多数已经弄明白了!还有下面的是怎么回事!procedure TForm1.UseThreadClick(Sender: TObject);
    var
      hThread:THandle;
      ThreadID:DWord;
    begin,@ThreadFunc
      hThread:=CreateThread(nil,0,@ThreadFunc,nil,0,threadID);//那这里的 @ThreadFunc是怎么回事?
      if hthread = 0 then
        MessageBox(Handle,'no thread',nil,MB_OK);
    end;
      

  5.   

    @ThreadFunc,它是函数指针,回调函数了
      

  6.   

    当然,
    这些东西都是windows的API即使是Delphi编程也要对系统API很熟悉