X
xhj12077021
Unregistered / Unconfirmed
GUEST, unregistred user!
我看到关于图片显示的资料,正好我也要用,可是我怎么调试都有问题?
在窗体上分别加入一个 FileListBox组件、一个DirectoryListBox组件,和一个 DriveComboBox组件,然后分别设置 DriveComboBox组件的DirList属性为DirectoryListBox1,DirectoryListBox1组件的FileList属性为FileListBox1。
我这里在网上看到用控件数组来显示的代码,我调试一直有问题。在:
Images.Picture.LoadFromFile(Form1.FileListBox1.Items[startindex+i]);//读入图像
Images.Show;//显示图像
Labels.Caption:=Form1.FileListBox1.Items[startindex+i];//
在Images出显示:
[Error] Unit1.pas(44): Record, object or class type required
那位大哥帮忙看看
原代码::
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,FileCtrl, StdCtrls;
type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
procedure FormCreate(Sender: TObject);
procedure DirectoryListBox1Change(Sender: TObject);
procedure FileListBox1Change(Sender: TObject);
private
{ Private declarations }
public
index:integer;
{ Public declarations }
end;
var
Form1: TForm1;
panels: array[0..15] of TPanel;//定义控件数组
images: array[0..15] of TImage;
Labels: array[0..15] of Tlabel;
startindex:integer;//显示第一个图像的标志
imageflag:Boolean;
implementation
{$R *.dfm}
procedure viewpicture;
var i,j:integer;
begin
j:=Form1.FilelistBox1.items.Count-startindex;
if j>16 then j:=16;
for i:=0 to j-1 do
Begin
Images.Picture.LoadFromFile(Form1.FileListBox1.Items[startindex+i]);//读入图像
Images.Show;//显示图像
Labels.Caption:=Form1.FileListBox1.Items[startindex+i];//显示文件名
end;
for i:=j to 15 do
begin
Images.Hide;//隐藏显示不下的图像
Labels.Caption:='';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
startindex:=0;
For i:=0 to 15 Do
begin
panels:=TPanel.Create(self);//动态建立Panel组件
panels.Parent:=self;
panels.Left:=1+(i mod 4)*100;//设置15个panel组件的属性
panels.Top:=10+(i div 4)*124;
panels.Width:=100;
panels.Height:=100;
panels.BevelInner:=bvLowered;
panels.BevelOuter:=bvRaised;
panels.Caption:='';
labels:=Tlabel.Create(self);//动态建立15个Label组件用于显示图像的文件名
labels.Parent:=self;
labels.Left:=5+(i mod 4)*100;//分别设置15个Label组件的属性
labels.Top:=115+(i div 4 )*124;
labels.Width:=50;
labels.Height:=17;
labels.Caption:='';
images:=TImage.Create(self);//动态建立15个Label组件用于显示图像
images.Parent:=panels;
images.AutoSize:=True;//设置各Image组件的相关属性
images.Align:=alClient;
images.Center:=True;
images.Stretch:=True;
end;
if FileListBox1.Items.Count<>0 then//如果 该目录中有图像文件
begin
viewpicture;//显示图像
imageflag:=True;//有图像标志设为真
end
else imageflag:=False;//设为无图状态
end;
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
startindex:=0;
end;
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
startindex:=FileListBox1.itemindex;
if startindex=-1 then startindex:=0;
index:=FileListBox1.items.Count;//获得图像文件总数
if FileListBox1.items.Count=0 then //无图
begin
if imageflag=False then exit;
viewpicture;
imageflag:=False
end
else begin
imageflag:=True;
viewpicture;
end;
end;
end.
在窗体上分别加入一个 FileListBox组件、一个DirectoryListBox组件,和一个 DriveComboBox组件,然后分别设置 DriveComboBox组件的DirList属性为DirectoryListBox1,DirectoryListBox1组件的FileList属性为FileListBox1。
我这里在网上看到用控件数组来显示的代码,我调试一直有问题。在:
Images.Picture.LoadFromFile(Form1.FileListBox1.Items[startindex+i]);//读入图像
Images.Show;//显示图像
Labels.Caption:=Form1.FileListBox1.Items[startindex+i];//
在Images出显示:
[Error] Unit1.pas(44): Record, object or class type required
那位大哥帮忙看看
原代码::
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,FileCtrl, StdCtrls;
type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
procedure FormCreate(Sender: TObject);
procedure DirectoryListBox1Change(Sender: TObject);
procedure FileListBox1Change(Sender: TObject);
private
{ Private declarations }
public
index:integer;
{ Public declarations }
end;
var
Form1: TForm1;
panels: array[0..15] of TPanel;//定义控件数组
images: array[0..15] of TImage;
Labels: array[0..15] of Tlabel;
startindex:integer;//显示第一个图像的标志
imageflag:Boolean;
implementation
{$R *.dfm}
procedure viewpicture;
var i,j:integer;
begin
j:=Form1.FilelistBox1.items.Count-startindex;
if j>16 then j:=16;
for i:=0 to j-1 do
Begin
Images.Picture.LoadFromFile(Form1.FileListBox1.Items[startindex+i]);//读入图像
Images.Show;//显示图像
Labels.Caption:=Form1.FileListBox1.Items[startindex+i];//显示文件名
end;
for i:=j to 15 do
begin
Images.Hide;//隐藏显示不下的图像
Labels.Caption:='';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
startindex:=0;
For i:=0 to 15 Do
begin
panels:=TPanel.Create(self);//动态建立Panel组件
panels.Parent:=self;
panels.Left:=1+(i mod 4)*100;//设置15个panel组件的属性
panels.Top:=10+(i div 4)*124;
panels.Width:=100;
panels.Height:=100;
panels.BevelInner:=bvLowered;
panels.BevelOuter:=bvRaised;
panels.Caption:='';
labels:=Tlabel.Create(self);//动态建立15个Label组件用于显示图像的文件名
labels.Parent:=self;
labels.Left:=5+(i mod 4)*100;//分别设置15个Label组件的属性
labels.Top:=115+(i div 4 )*124;
labels.Width:=50;
labels.Height:=17;
labels.Caption:='';
images:=TImage.Create(self);//动态建立15个Label组件用于显示图像
images.Parent:=panels;
images.AutoSize:=True;//设置各Image组件的相关属性
images.Align:=alClient;
images.Center:=True;
images.Stretch:=True;
end;
if FileListBox1.Items.Count<>0 then//如果 该目录中有图像文件
begin
viewpicture;//显示图像
imageflag:=True;//有图像标志设为真
end
else imageflag:=False;//设为无图状态
end;
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
startindex:=0;
end;
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
startindex:=FileListBox1.itemindex;
if startindex=-1 then startindex:=0;
index:=FileListBox1.items.Count;//获得图像文件总数
if FileListBox1.items.Count=0 then //无图
begin
if imageflag=False then exit;
viewpicture;
imageflag:=False
end
else begin
imageflag:=True;
viewpicture;
end;
end;
end.