Delphi¶àÏß³Ìѧϰ£¨3£©£ºÏß³Ìͬ²½µÄÔÒò
ÔÚʹÓöàÏ̵߳Äʱºò£¬Èç¹û¶àÏ̶߳Ôij¸öÌØ¶¨µÄ¹«¹²Êý¾Ý»ò×ÊÔ´½øÐзÃÎÊ£¬ÐèÒª¶Ô¶àÏ߳̽øÐÐе÷²Ù×÷£¬½Ð×öÏß³Ìͬ²½¡£
ÀýÈ磺Èý¸öÏ̷ֱ߳ðÑ»·µØÏòListBoxÖÐдÈëÊý¾Ý¡£Ã»ÓнøÐÐͬ²½Ê±£¬Ð´ÈëµÄ˳ÐòÊDz»È·¶¨µÄ¡£
{Ö÷´°Ìå´úÂë}
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses MyThread;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
TMyThread.Create(False);
TMyThread.Create(False);
TMyThread.Create(False);
end;
end.{¶àÏ̴߳úÂë}
unit MyThread;
interface
uses
Classes,StdCtrls,SysUtils,Windows;
type
TMyThread = class(TThread)
private
{ Private declarations }
str:String;
procedure AddList;
protected
procedure Execute; override;
end;
implementation
uses Unit2;
{ TMyThread }
procedure TMyThread.AddList;
begin
Form2.ListBox1.Items.Add(str);
end;
procedure TMyThread.Execute;
var
i:Integer;
begin
{ Place thread code here }
for i := 0 to 99 do
begin
if not Terminated then
begin
str:=Format('Ïß³ÌID:%d£¬µÚ%d¸öÑ»·¡£',[GetCurrentThreadId,i]);
Synchronize(AddList);
end;
end;
end;
end.
Èý¸öÏ̸߳ù¾Ý·ÖÅäµ½µÄCPUʱ¼äµÄ˳ÐòÏòListBoxÖÐдÈëÊý¾Ý¡£ÕâÀïµÄ¹«¹²×ÊÔ´ÊÇListBox¡£
¿ÉÒÔ½«Õâ¸ö¹«¹²µÄÀä×ÊÔ´±ÈÓ÷Ϊһ¸öͼÊé¹Ý£¬Ï̱߳ÈÓ÷Ϊ½èÊé¿´ÊéµÄÈËÔ±¡£ÄÇôûÓÐͬ²½´¦ÀíµÄÇé¿öÏ£¬¾ÍºÃÏñͼÊé¹ÝÍêÈ«¿ª·Å£¬Ã»ÓÐÈ˹ÜÀí£¬Ã¿¸öÈ˶¼¿ÉÒÔ·ÃÎÊÕâ¸öͼÊé¹Ý¡£¿´ÆðÀ´ÂÒÔãÔãµÄ£¬¶øÇÒµ±Ä³ÈËÏë½èÊéAµÄ»°£¬²éѯµÄʱºòÊéA»¹ÔÚ£¬µ±ËûÈ¥½èµÄʱºò¿ÉÄܱ»ÁíÒ»ÈËÒѽè×ß¡£
ΪÁ˸üºÃ¹ÜÀíµÄÐèÒª£¨Ä³Ð©¶Ô¹«¹²×ÊÔ´µÄ·ÃÎʱØÐëÖð¸öÏ̴߳¦Àí£¬²Å²»»á³ö´í£©£¬ÕâÀï¾ÍÒªÓõ½Í¬²½£¬¼´²éѯºÍ½èÊéÕâÁ½¸ö²½ÖèÒªÒ»ÆðÍê³É£¬µÈÒ»¸
Ïà¹ØÎĵµ£º
ÔÚ±àÖÆÁËÒ»¸öÓ¦ÓóÌÐòºóµÄά»¤½×¶Î£¬ÎÒÃÇ»áÃæÁÙ¸øÓ¦ÓóÌÐòÉý¼¶µÄ¹¤×÷.ÎÞÒÉ£¬ÊÖ¹¤Éý¼¶µÄ¹¤×÷ÊÇÊ®·Ö·±ËöµÄ£¬Äã¿ÉÄÜ»áÐèÒªµ½Óû§µÄ»úÆ÷ÉÏÈ¥¸üÐÂÎļþ.¿ÉÊÇ£¬Èç¹ûÄܱàÒ»¸ö×Ô¶¯Éý¼¶³ÌÐò£¬·ÅÔÚÍøÂçÉÏ£¬ÈÃÓû§ÏÂÔØ£¬Ö»ÐèÖ´ÐÐһϾÍÍê³ÉÉý¼¶¹¤×÷£¬²»ÊǺܷ½±ãÂð£¿Æäʵ£¬ÓÃDelphi¿ÉÒԺܷ½±ãµØ±àÖÆ³öÕâÑùÒ»¸öµÄ³ÌÐò.
ÒÔÏÂÊÇÎÒÃǵÄÀý×Ó£ ......
һЩ»ù´¡µÄÎÊÌâÎÒ²»ÔÙ׸ÊöÁË£¬²éÔİïÖúÎĵµ£¨Object Pascal SDL Doc.chm£©ÏÔÈ»±ÈÔÚÕâ¿´ÎÒºú³¶ºÏÊʵöࡣÄÇЩ»ÏñËØ£¬»ñÈ¡ÏñËØÐÅÏ¢£¬ÏÔʾBMPÎļþ¶àÊýʱºòÖ»Òª°ÑÄÇЩ´úÂë¸´ÖÆ¹ýÀ´»ù±¾¾ÍÄܹ¤×÷¡£ÏÂÃæËµµÄÊÇÔõÑùÏÔʾÖÐÎÄ¡£
ÆäʵSDL¼ÓÉÏttfÖ§³Öʱ£¨ÐèÒª½«¶ÔÓ¦µÄdllÎļþÌí¼Óµ½¹¤³ÌĿ¼ÀÊÇÍêÈ«¿ÉÒÔÏÔʾÖÐÎĵ쬼òÌåºÍ·±Ì嶼ûΠ......
CTRL+SPACE ´úÂ벹ȫ£¬ºÜºÃÓõÄ(ÏȸÄÁËÊäÈë·¨Èȼü)
CTRL+SHIFT+C ±àдÉêÃ÷»òÕß²¹ÉϺ¯Êý
CTRL+SHIFT+↑(↓) ÔÚ¹ý³Ì¡¢º¯Êý¡¢Ê¼þÄÚ²¿, ¿ÉÌøÔ¾µ½ÏàÓ¦µÄ¹ý³Ì¡¢º¯Êý¡¢Ê¼þµÄ¶¨Ò壨ÔÚINTERFACEºÍIMPLEMENTATIONÖ®¼äÀ´»ØÇл»£©
CTRL+SHIFT+G ²åÈëGUID
CTRL+J (µ¯³öDELPHIÓï¾äÌáʾ´°¿Ú£¬Ñ¡ÔñËùÐèÓï¾ä½«×Ô¶¯Íê³ÉÒ»Ìõ ......
TThreadÊÇÒ»¸ö³éÏóÀà,ÓÃÓÚÔÚdelphiÖд´½¨Ï̡߳£
´´½¨Ò»¸öTThreadµÄ×ÓÀà¶ÔÏó¼´Ï൱ÓÚ´´½¨Ò»¸öÏ̡߳£¡¡¡¡
µ±Ò»¸öÓ¦ÓóÌÐòÔËÐÐʱ£¬Ó¦ÓóÌÐò¾Í±»ÔØÈëÄÚ´æ×¼±¸Ö´ÐС£´Ëʱ£¬Ëü³ÉΪ°üº¬Ò»¸ö»ò¶à¸öÏ̵߳Ľø³Ì¡£Ïß³ÌÖ´ÐÐÓ¦ÓóÌÐòµÄ²¿·ÖÄÚÈÝ£¬²¢ÓɲÙ×÷ϵͳ·ÖÅäCPUʱ¼ä¡£Í¬Ò»½ø³ÌµÄËùÓÐÏ̹߳²ÏíͬһµØÖ·¿Õ¼ä£¬¿ÉÒÔ·ÃÎʽø³ÌµÄÈ«¾Ö±äÁ¿ ......