Delphi¶àÏß³Ìѧϰ£¨2£©£ºDelphiÖеĶàÏß³ÌÀàTThread¡£
2010-02-22 17:08:46
Delphi°Ñ¶àÏß³ÌÏà¹ØµÄAPI·â×°ÔÚTThreadÕâ¸öÀàÖУ¬¿ÉÒÔ·½±ãʵÏÖ¶àÏß³ÌÔËÓá£Ê×ÏÈ¿´ÏÂTThreadµÄÉùÃ÷£º
TThread = class
private
FHandle: THandle;
FThreadID: THandle;
FCreateSuspended: Boolean;
FTerminated: Boolean;
FSuspended: Boolean;
FFreeOnTerminate: Boolean;
FFinished: Boolean;
FReturnValue: Integer;
FOnTerminate: TNotifyEvent;
FSynchronize: TSynchronizeRecord;
FFatalException: TObject;
procedure CallOnTerminate;
class procedure Synchronize(ASyncRec: PSynchronizeRecord); overload;
function GetPriority: TThreadPriority;
procedure SetPriority(Value: TThreadPriority);
procedure SetSuspended(Value: Boolean);
protected
procedure CheckThreadError(ErrCode: Integer); overload;
procedure CheckThreadError(Success: Boolean); overload;
procedure DoTerminate; virtual;
procedure Execute; virtual; abstract;
procedure Synchronize(Method: TThreadMethod); overload;
property ReturnValue: Integer read FReturnValue write FReturnValue;
property Terminated: Boolean read FTerminated;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
procedure AfterConstruction; override;
procedure Resume;
procedure Suspend;
procedure Terminate;
function WaitFor: LongWord;
class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod); overload;
class procedure StaticSynchronize(AThread: TThread; AMethod: TThreadMethod);
property FatalException: TObject read FFatalException;
property FreeOnTerminate: Boolean read FFreeOnTerminate write FFreeOnTerminate;
property Handle: THandle read FHandle;
property Priority: TThreadPriority read GetPriority write SetPriority;
property Suspended: Boolean read FSuspended write SetSuspended;
property ThreadID: THandle read FThreadID;
property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
end;
ÓÉÓÚTThreadÊÇÒ»¸ö³éÏóÀ࣬ËùÒÔ
Ïà¹ØÎĵµ£º
ʵ¼ÊÉÏÕâ¸öÃû×Ö½Ð[SDL & Delphi]Ò²²»³ÉÎÊÌ⣬ ÒòΪ³ýÁËDelphiËƺõҲûÓÐÄĸöÁ÷ÐеĿª·¢¹¤¾ßÓõÄÊÇPascalÓïÑÔ¡£
SDLÆäʵÎÒҲֻѧÁ˲»µ½Á½ÐÇÆÚ¶øÒÑ¡£¸Õ¿ªÊ¼ÎÒÏëÊÔͼÓÃVC£¬ÒòΪÕâÑù×ÊÁÏ×îÈ«£¬Ò²ºÜºÃÕÒ£¬µ«Ì«¾ÃûÓÃVCÏÖÔÚ¿´CµÄ´úÂëÓеãÀ§ÄÑ£¨->Õâ¸öËã·ûÊǸÉÂðµÄÀ´×Å……£©¡£Æäʵ×÷Ϊһ¸öרҵ²»ÊǼÆËã»úµÄÈË ......
ÓÃDelphi ʵÏÖ´®¿ÚͨѶ£¬³£Óõļ¸ÖÖ·½·¨Îª£ºÊ¹ÓÿؼþÈçMSCOMMºÍSPCOMM£¬Ê¹ÓÃAPIº¯Êý»òÕßÔÚDelphi Öе÷ÓÃÆäËü´®¿ÚͨѶ³ÌÐò¡£ÀûÓÃAPI±àд´®¿ÚͨÐųÌÐò½ÏΪ¸´ÔÓ£¬ÐèÒªÕÆÎÕ´óÁ¿Í¨ÐÅ֪ʶ£¬ÆäÓŵãÊÇ¿ÉʵÏֵŦÄܸüÇ¿´ó£¬Ó¦ÓÃÃæ¸ü¹ã·º£¬¸üÊʺÏÓÚ±àд½ÏΪ¸´ÔÓ µÄµÍ²ã´ÎͨÐųÌÐò¡£Ïà±È½Ï¶øÑÔ£¬ÀûÓÃSPComm¿Ø¼þÔòÏà¶Ô½Ï¼òµ¥£¬¸Ã¿Ø¼þ¾ßÓ ......
ʹÓÃdelphi¶àÄê,ǰЩÌìºöÈ»Óöµ½²»»ástringתpbyte,ºÜÊÇʧÂä,´Ëʱ¶ÔÓÚ±à³Ì»ù±¾¹¦µÄÖØÒªÐÔÉîÓÐÌå»á.ÕâÆäÖÐÓõ½MOVEº¯Êý.
ʹÓÃdelphi¶àÄê,ǰЩÌìºöÈ»Óöµ½²»»ástringתpbyte,ºÜÊÇʧÂä,´Ëʱ¶ÔÓÚ±à³Ì»ù±¾¹¦µÄÖØÒªÐÔÉîÓÐÌå»á.ÕâÆäÖÐÓõ½MOVEº¯Êý.
¸ãÁ˺ÃÒ»»á²Å¸ãÃ÷°×ÆäÓ÷¨.ËùÒÔÏëÌù³öÀ´°ïÖúÐèÒª°ïÖúµÄÈË.
var
&nb ......
CTRL+SPACE ´úÂ벹ȫ£¬ºÜºÃÓõÄ(ÏȸÄÁËÊäÈë·¨Èȼü)
CTRL+SHIFT+C ±àдÉêÃ÷»òÕß²¹ÉϺ¯Êý
CTRL+SHIFT+↑(↓) ÔÚ¹ý³Ì¡¢º¯Êý¡¢Ê¼þÄÚ²¿, ¿ÉÌøÔ¾µ½ÏàÓ¦µÄ¹ý³Ì¡¢º¯Êý¡¢Ê¼þµÄ¶¨Ò壨ÔÚINTERFACEºÍIMPLEMENTATIONÖ®¼äÀ´»ØÇл»£©
CTRL+SHIFT+G ²åÈëGUID
CTRL+J (µ¯³öDELPHIÓï¾äÌáʾ´°¿Ú£¬Ñ¡ÔñËùÐèÓï¾ä½«×Ô¶¯Íê³ÉÒ»Ìõ ......
TThreadÊÇÒ»¸ö³éÏóÀà,ÓÃÓÚÔÚdelphiÖд´½¨Ï̡߳£
´´½¨Ò»¸öTThreadµÄ×ÓÀà¶ÔÏó¼´Ï൱ÓÚ´´½¨Ò»¸öÏ̡߳£¡¡¡¡
µ±Ò»¸öÓ¦ÓóÌÐòÔËÐÐʱ£¬Ó¦ÓóÌÐò¾Í±»ÔØÈëÄÚ´æ×¼±¸Ö´ÐС£´Ëʱ£¬Ëü³ÉΪ°üº¬Ò»¸ö»ò¶à¸öÏ̵߳Ľø³Ì¡£Ïß³ÌÖ´ÐÐÓ¦ÓóÌÐòµÄ²¿·ÖÄÚÈÝ£¬²¢ÓɲÙ×÷ϵͳ·ÖÅäCPUʱ¼ä¡£Í¬Ò»½ø³ÌµÄËùÓÐÏ̹߳²ÏíͬһµØÖ·¿Õ¼ä£¬¿ÉÒÔ·ÃÎʽø³ÌµÄÈ«¾Ö±äÁ¿ ......