const crMyCursor = 100;var MyIcon: TIcon;procedure TForm1.FormCreate(Sender: TObject); begin MyIcon := TIcon.Create; MyIcon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE('MyIcon')); Screen.Cursors[crMycursor] := LoadCursor(hInstance, MAKEINTRESOURCE('MyCursor')); Memo1.Cursor := crMyCursor; end;procedure TForm1.Button1Click(Sender: TObject); begin Application.Icon := MyIcon; end;procedure TForm1.FormDestroy(Sender: TObject); begin MyIcon.Free;{ MyCursor don't need to free because Delphi does it for us }end;end.
private BtnArr:Array[0..9]of TButton; procedure CreateBtns; procedrue FreeBtns; procedure BtnClick(Sender:TObject); ........ procedure TForm1.CreateBtns; var i:integer;begin for i:=Low(BtnArr) to HIgh(BtnArr) do begin BtnArr[i]:=TButton.Create(Self); with BtnArr[i] do begin Parent:=Self; Caption:= 'I am Button'+inttostr(i); Top:=i*20; OnClick:=BtnClick; end; end; end; procedure TForm1.FreeBtns; var i:integer;begin for i:=Low(BtnArr) to HIgh(BtnArr) do begin BtnArr[i.Free; end; end; procedure TForm1.BtnClick(Sender:TObject); begin ShowMessage((Sender as TButton).Caption)); end;
crMyCursor = 100;var
MyIcon: TIcon;procedure TForm1.FormCreate(Sender: TObject);
begin
MyIcon := TIcon.Create;
MyIcon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE('MyIcon')); Screen.Cursors[crMycursor] := LoadCursor(hInstance, MAKEINTRESOURCE('MyCursor'));
Memo1.Cursor := crMyCursor;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Icon := MyIcon;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
MyIcon.Free;{ MyCursor don't need to free because Delphi does it for us }end;end.
BtnArr:Array[0..9]of TButton;
procedure CreateBtns;
procedrue FreeBtns;
procedure BtnClick(Sender:TObject);
........
procedure TForm1.CreateBtns;
var
i:integer;begin
for i:=Low(BtnArr) to HIgh(BtnArr) do
begin
BtnArr[i]:=TButton.Create(Self);
with BtnArr[i] do
begin
Parent:=Self;
Caption:= 'I am Button'+inttostr(i);
Top:=i*20;
OnClick:=BtnClick;
end;
end;
end;
procedure TForm1.FreeBtns;
var
i:integer;begin
for i:=Low(BtnArr) to HIgh(BtnArr) do
begin
BtnArr[i.Free;
end;
end;
procedure TForm1.BtnClick(Sender:TObject);
begin
ShowMessage((Sender as TButton).Caption));
end;
简单点说如 marf_cn(吗啡)
同意 SydPink(希望不再敲键盘!)
别忘了释放