1.delphi å¦ä½å©ç¨å¾ªç¯å建å¤ä¸ªä¸åçTimageã
2.Delphi å¤çº¿ç¨çä¸ä¸ªä»£ç å¦ä½å
3.delphiçTListï¼TStringListï¼TObjectListçåºå«åèç³»
delphi å¦ä½å©ç¨å¾ªç¯å建å¤ä¸ªä¸åçTimageã
imglist:TList;//åæ¾imageç容å¨
Procedure intiImage;//å¨æå建Timageçè¿ç¨ï¼
//å建timage;
var
img1:TImage;
widthimg1,c 魂斗罗源码heightimg1,colimg1,rowimg1,col,row,i:Integer;
widthLength,heightLength:Integer;
begin
colimg1:=;// Imageçåæ°
rowimg1:=;// Imageçè¡æ°
widthimg1:=;// Imageç宽
heightimg1:=;// Imageçé«
//Imageä¸Imageä¹é´çé´éå¨å®½
widthLength:=(pnl1.ClientWidth-widthimg1*colimg1) div (colimg1+1);
//Imageä¸Imageä¹é´çé´éå¨é«
heightLength:=(pnl1.ClientHeight-heightimg1*rowimg1)div (rowimg1+1);
imgList:=TList.Create;
for I := 0 to colimg1 * rowimg1-1 do
begin
img1:=TImage.Create(Self);
col:= i mod colimg1;
row:= i div colimg1;
img1.Left:=col * widthimg1+(col+1)*widthLength;
img1.Top:=row * heightimg1+(row+1)*heightLength;
img1.Width:=widthimg1;
img1.Height:=heightimg1;
// img1.Picture.LoadFromFile('C:\image\1.jpg');//è¿ä¸ªåºè¯¥åå¨imgClickäºä»¶ä¸
img1.OnClick:=imgClick;//imgClickäºä»¶æ¯èªå®ä¹ç
img1.Parent:=pnl1;
imgList.Add(img1);
end;
end;
//ä» ä¾åè
Delphi å¤çº¿ç¨çä¸ä¸ªä»£ç å¦ä½å
åå 天å好æ个客æ·å«æç¨DELPHI帮å¿å个线ç¨ä¾åï¼ç»ä½ çç
//主çªä½
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
//线ç¨å表,åTlistå·®ä¸å¤,å¤äºä¸äºå¤çº¿ç¨åæ¥å¤çæ¹æ³
GvThreadList : TThreadList;
implementation
uses Unit2;
{ $R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
GvThreadList := TThreadList.Create;
Label1.Caption := '线ç¨æ°:';
Button1.Caption := 'å建';
Button2.Caption := 'åæ¢';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,ICount : Integer;
MyLIst : TList;
MyRcThread : RcThread;
begin
ICount := StrToInt(edit1.Text);
//è¿éä¸ç¨MyListä¹ä¸æ ·,å¯ä»¥ç´æ¥ç¨GvThreadList.Add(P),让å¦ä¹ è æ个LockListæ¹æ³
MyList := GvThreadList.LockList;
for i :=0 to ICount-1 do
begin
MyRcThread := RcThread.Create(false,memo1,'线ç¨ç¼å·:'+IntTostr(i));
//å°æå建ç线ç¨æ·»å å°å表ä¸,æ¹ä¾¿ç®¡ç
MyList.Add(MyRcThread);
end;
GvThreadList.UnlockList;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i : integer;
MyLIst : TList;
MyRcThread : RcThread;
begin
//å¤ä¸ªå°æ¹åæ¶è®¿é®ä¸ä¸ªå表æ¶,å¯ä»¥ç¨ThreadListç线ç¨éæ¹æ³(临ç),é¿å å¤çº¿ç¨è®¿é®åé导è´åéåå¼åºé
MyList := GvThreadList.LockList;
for i := 0 to Mylist.Count -1 do
begin
MyRcThread:=MyList[0];
MyRcThread.Terminate;
Mylist.Delete(0);
end;
MyList.Clear;
//解é
GvThreadList.UnlockList;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Button2.Click;
GvThreadList.Free;
end;
end.
//线ç¨åå
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
//å®ä¹çº¿ç¨,ç®åç举ä¾å¦ä½å建/è°ç¨çº¿ç¨,
type
RcThread = class(TThread)
private
procedure RefreshMainForm;
public
MyCount: integer ;
MyThreadTally : string;
Mymemo : Tmemo;
//å建åæ°:线ç¨æ¯å¦æèµ·,MEMO,线ç¨æ è®°
constructor Create(CreateSuspended:Boolean;memo:Tmemo;ThreadTally:String);reintroduce;
destructor Destroy(); override;
protected
procedure Execute(); override;
end;
implementation
uses Unit1;
{ RcThread }
//å建
constructor RcThread.Create(CreateSuspended: Boolean;memo:Tmemo;ThreadTally:String);
begin
MyCount := 0;
Mymemo := memo;
MYThreadTally :=ThreadTally;
inherited Create(CreateSuspended);
end;
//éæ¾
destructor RcThread.Destroy;
begin
MyMemo.Lines.Add(MyThreadTally+'éæ¾');
inherited;
end;
//æ§è¡
procedure RcThread.Execute;
begin
while True do
begin
//åæ¢,å¯ä»¥æ ¹æ®èªå·±è¦å¤æçæ¡ä»¶å»å¤æ(if....then break;)
if (self.Terminated = true) then
Free;
//线ç¨æ¯è±ªç§æ§è¡ä¸æ¬¡,以å è¿å¤å ç¨CPU
sleep();
//åæ¥
Synchronize(RefreshMainForm);
end;
end;
procedure RcThread.RefreshMainForm;
begin
//ç®å举ä¾,å¾ä¼ éçMEMOä¸åå½å线ç¨æ§è¡äºç¬¬å 次
Inc(MyCount);
Mymemo.Lines.Add(MyThreadTally+' æ§è¡ç¬¬'+IntToStr(MyCount)+'次');
Application.ProcessMessages;
end;
end.
delphiçTListï¼TStringListï¼TObjectListçåºå«åèç³»
ä¸åäºTListç±»ï¼TObjectListç±»çAdd, Remove, IndexOf, Insertçæ¹æ³é½éè¦ä¼ éTObject对象ä½ä¸ºåæ°ï¼ç±äºæäºç¼è¯æç强类åæ£æ¥ï¼ä½¿å¾TObjectListæ¯TListæ´éåä¿å对象ãæ¤å¤TObjectList对象æOwnsObjectså±æ§ãå½è®¾å®ä¸ºTrue (é»è®¤å¼)ï¼åTListç±»ä¸åï¼TObjectList对象å°éæ¯ä»»ä½ä»å表ä¸å é¤ç对象ãæ 论æ¯è°ç¨Delete, Remove, Clear æ¹æ³ï¼è¿æ¯éæ¾TObjectList对象ï¼é½å°éæ¯å表ä¸ç对象ãæäºTObjectListç±»ï¼æ们就åä¹ä¸ç¨ä½¿ç¨å¾ªç¯æ¥éæ¾äºå¯¹è±¡ãè¿å°±é¿å äºéæ¾é¾è¡¨å¯¹è±¡æ¶ï¼ç±äºå¿è®°éæ¾é¾è¡¨ä¸ç对象è导è´çå åæ³æ¼ã å¦å¤è¦æ³¨æçæ¯OwnsObjectså±æ§ä¸ä¼å½±åå°Extractæ¹æ³ï¼TObjectListçExtractæ¹æ³è¡ä¸ºç±»ä¼¼äºTListï¼åªæ¯ä»å表ä¸ç§»é¤å¯¹è±¡å¼ç¨ï¼èä¸ä¼éæ¯å¯¹è±¡ã
ããå¨TstringListéï¼é£äºString被ä¸è¡ä¸è¡å°å¨åã TstringList.Textè¿åå ¨é¨çStringãå¦æ第ä¸ãäºãä¸è¡åå«æ¯\'aa\'ã\'bb\'ã\'cc\' çè¯ï¼é£ä¹Text è¿åçæ¯â\'aa\'+##+\'bb\'+##+\'cc\'+##â ï¼ä¸å æ¬åå¼å·ï¼ãææçStringé½è¢«TstringListç¨å车åæ¢è¡ç¬¦ï¼##ï¼è¿æ¥äºèµ·æ¥ãå¦æä¾æ¬¡åTextèµå¼çè¯ï¼Textå°±ä¼ è¢«èªå¨å°åå²æè¡å¨åå¨TstringList éãè¿å åå°ä½ç°åºTstringListçä¸ä¸ªå¾å®ç¨çä»·å¼ï¼å®è½è®©æ们éè¡å¤çStringãåå¦æ们è¦æä½ç¬¬4è¡ï¼åªéæä½ TstringList[3]ãç¸ä¿¡å¤§å®¶ä¼é®ï¼TstringListæææ¯ä¸ä¸ªç±»ï¼ä¸ºä»ä¹è½å½æ°ç»é£æ ·åç¨å¢ï¼å ¶å®ï¼æ们å¨å TstringList[3]çæ¶åï¼å°±æ¯å¨åTstringList.Strings[3]ãStringsæ¯TstringListçä¸ä¸ªç¼ºçå±æ§ã æ°ç»æ§ç缺çå±æ§å°±æ¯è¿æ ·å使ç¨çãå¦æ大家å¨ç¼åç±»çæ¶åè¦ç¨å°è¿ä¹ä¸ä¸ªåè½çè¯ï¼å¯ä»¥åç §å¦ä¸æ¹æ³ï¼
ããproperty AProperty[I: Integer] read *** write ***;
ããdefault;ã
ããStrings æ¯ä¸ä¸ªå¯è¯»åçå±æ§ãè¿ä¹å°±æ¯è¯´ï¼å¤§å®¶ä¸ä» å¯ä»¥è·å¾ç¬¬N è¡çå 容ï¼ä¹å¯ä»¥æ¹å第N è¡çå 容ãå æ¤æ们éè¦ç¥éTstringList éS t r i n g çæ»è¡æ°ãTstringListçå±æ§Countåå¯ä»¥æ»¡è¶³æ们çéè¦ã
ããä¸é¢å·²ç»è¯´è¿ï¼Textæ¯ä¸ä¸ªè¿åææå符串çå±æ§ãåTextèµå¼ æ¶ï¼TstringListè½å¤èªå¨å°æTextåæä¸è¡ä¸è¡çï¼ç¶åå¨åå¨TstringListéï¼å½ç¶ï¼TstringListéé¢å¹¶ä¸å®å ¨æ¯è¿ä¹ å¨åçï¼è¯¦ç»è¿ç¨å»ºè®®çTstringListåTStringsç代ç ï¼ãè¿æ ·ï¼Stringsè¿åçå符串就æ¯æ²¡
ããæå车åæ¢è¡çãä½æ¯ï¼å¦ææ们åStringsèµå¼çå符串æå车åæ¢è¡ï¼é£ ä¹ä¼åºç°ä»ä¹æ åµå¢ï¼æ¤æ¶ï¼Stringså°±ä¼æé£ä¸ªå符串ææå è¡ï¼æå ¥å°åæ¥çä½ç½®ä¸ãå¦æTstringListåªæè¿ä¹äºåè½çè¯ï¼é£æå°±ä¸å¿ ä¸ é¨æ¿åºæ¥è®²äºââææ¯è¯´ï¼TstringListè½è®©æ们任æ
ããå°æå ¥æå é¤æè¡ï¼è¿å°±è¦ç¨å°TstringListæä¾çæ¹æ³ã
ããfunction Add(const S: string): Integer;
ããprocedure Append(const S: string);
ããAddæ¹æ³åTstringListçæ«å°¾æ·»å ä¸è¡Stringï¼å¨è¿éåä¸é¢æ们é½å设è¾å ¥çå符串没æå车åæ¢è¡ï¼å¦åStringå°è¢«åå²ï¼ãåæ°S 代表çæ¯è¦æå ¥çå符串çå 容ãAddçè¿åå¼ä»£è¡¨äºæ°çå符串å¨TstringListçä½ç½®ââä¹å°±æ¯æåä¸è¡çä½ç½®ï¼å³æ°çCount åå»ä¸ã
ããAppend æ¹æ³ä¸Add å¯ä¸ä¸åçå°æ¹æ¯æ²¡æè¿åå¼ã
ããprocedure Insert(Index: Integer; const S: string);
ããInsertæ¹æ³åTstringListæå ¥ä¸è¡å符串ãå¨Insertéï¼æ们å¯ä»¥èªç±å°éæ©å符串æå ¥çä½ç½®ãåæ°S 代表è¦æå ¥çå符串çå 容ï¼Index 代表è¦æå ¥çä½ç½®ã
ããprocedure Delete(Index: Integer);
ããDelete æ¹æ³å é¤æè¡å符串ï¼æ们åæ ·å¯ä»¥èªç±å°éæ©å é¤ä»»æä¸è¡å符串ãåæ°Index代表è¦å é¤çé£ä¸è¡å符串çä½ç½®ã
2024-11-27 12:37
2024-11-27 12:36
2024-11-27 12:25
2024-11-27 12:16
2024-11-27 11:50
2024-11-27 10:34