H
handsome1234
Unregistered / Unconfirmed
GUEST, unregistred user!
//我抄书上的一个程序有些问题不懂
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
TabControl1: TTabControl;
ImageList1: TImageList;
ListView1: TListView;
Label1: TLabel;
Image1: TImage;
procedure TabControl1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
private
{ Private declarations }
public
{ Public declarations }
end;
type earthyplanet=record
planet:string;
R:integer; //半径
RCycle:double; //周期
pictureFileName:String;
end;
infomation= array[0..3] of earthyplanet;
var
Form1: TForm1;
const info:infomation=
((planet:'水星';R:2440;rcycle:58.65;picturefilename:'水星.bmp'),
(planet:'金星';R:6025;rcycle:243.0;picturefilename:'金星.bmp'),
(planet:'地球';R:6378;Rcycle:1.0;picturefilename:'地球.bmp'),
(planet:'火星';R:3395;rcycle:1.0257;picturefilename:'火星.bmp'));
implementation
{$R *.DFM}
procedure TForm1.TabControl1Change(Sender: TObject);
begin
image1.picture.loadfromfile(info[tabcontrol1.tabindex].picturefilename);
listview1.selected:=listview1.items.item[tabcontrol1.tabindex];
//单步调试模式下:为什么我在应用程序中改变了TabControl1的焦点后
//直接跳到ListView1Change()并且执行该函数2-3次又返回到下面的语句????
listview1.setfocus;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
listitem:TlistItem;
newcolumn:Tlistcolumn;
begin
image1.picture.loadfromfile(info[0].picturefilename);
with ListView1 do
begin
RowSelect:=true;
newColumn:=Columns.add;
newcolumn.caption:='自转周期(天)';
newcolumn.width:=100;
for i:=0 to 3 do
begin
listitem:=items.add;
listitem.imageindex:=i;
listitem.caption:=info[0].planet;
//单步调试时为什么执行了上面那句,就跳到:
//ListView1Change()??
listitem.subitems.add(inttostr(info.r));
listitem.subitems.add(floattostr(info.rcycle));
end;
Selected:=items.item[0];
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
listview1.setfocus;
end;
procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
//单步调试模式下,当我改变ListView1(单击焦点的下一行)
//为什么下面的函数体执行2-3次
begin
tabcontrol1.tabindex:=item.index;
image1.picture.loadfromfile(info[tabcontrol1.tabindex].picturefilename);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
TabControl1: TTabControl;
ImageList1: TImageList;
ListView1: TListView;
Label1: TLabel;
Image1: TImage;
procedure TabControl1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
private
{ Private declarations }
public
{ Public declarations }
end;
type earthyplanet=record
planet:string;
R:integer; //半径
RCycle:double; //周期
pictureFileName:String;
end;
infomation= array[0..3] of earthyplanet;
var
Form1: TForm1;
const info:infomation=
((planet:'水星';R:2440;rcycle:58.65;picturefilename:'水星.bmp'),
(planet:'金星';R:6025;rcycle:243.0;picturefilename:'金星.bmp'),
(planet:'地球';R:6378;Rcycle:1.0;picturefilename:'地球.bmp'),
(planet:'火星';R:3395;rcycle:1.0257;picturefilename:'火星.bmp'));
implementation
{$R *.DFM}
procedure TForm1.TabControl1Change(Sender: TObject);
begin
image1.picture.loadfromfile(info[tabcontrol1.tabindex].picturefilename);
listview1.selected:=listview1.items.item[tabcontrol1.tabindex];
//单步调试模式下:为什么我在应用程序中改变了TabControl1的焦点后
//直接跳到ListView1Change()并且执行该函数2-3次又返回到下面的语句????
listview1.setfocus;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
listitem:TlistItem;
newcolumn:Tlistcolumn;
begin
image1.picture.loadfromfile(info[0].picturefilename);
with ListView1 do
begin
RowSelect:=true;
newColumn:=Columns.add;
newcolumn.caption:='自转周期(天)';
newcolumn.width:=100;
for i:=0 to 3 do
begin
listitem:=items.add;
listitem.imageindex:=i;
listitem.caption:=info[0].planet;
//单步调试时为什么执行了上面那句,就跳到:
//ListView1Change()??
listitem.subitems.add(inttostr(info.r));
listitem.subitems.add(floattostr(info.rcycle));
end;
Selected:=items.item[0];
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
listview1.setfocus;
end;
procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
//单步调试模式下,当我改变ListView1(单击焦点的下一行)
//为什么下面的函数体执行2-3次
begin
tabcontrol1.tabindex:=item.index;
image1.picture.loadfromfile(info[tabcontrol1.tabindex].picturefilename);
end;
end.