我的程序代码在编译时一直给我带来麻烦。程序的想法只是创建一个将文本文件读入数组的过程。该按钮然后将显示它们在一个丰富的。程序中无效的类型转换
这里是原代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
ArrNames = array [1..10] of string;
ArrSales = array [1..10] of integer;
type
TForm1 = class(TForm)
btnShowData: TButton;
redt1: TRichEdit;
procedure btnShowDataClick(Sender: TObject);
private
public
{ Public declarations }
end;
Procedure Showdata;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure ShowData;
var c2u : textfile;
count : integer;
aNames : arrNames;
aSales : arrSales;
Begin
If FileExists('data.txt') <> true then
begin
Messagedlg('File does not exist', mtError, [mbOK], 0);
Exit;
end;
Count :=0;
AssignFile(c2u, 'data.txt');
Reset(c2u);
While Not EOF(c2u) do
begin
Inc(Count);
readln (c2u, aNames[count]);
readln (c2u, aSales[count]);
end;
Closefile(c2u);
End;
procedure TForm1.btnShowDataClick(Sender: TObject);
var J : integer;
aNames : arrNames;
aSales : arrSales;
begin
redt1.lines.add(aNames[J] +#9 + 'R' +IntToStr(aSales[J]));
end;
end.
是否有任何理由你没有使用TStringList - “德尔福”的方式来做到这一点? – 2013-03-19 20:36:44
你得到了什么*确切*错误信息? – 2013-03-19 20:37:17
尼克关于使用TStringList的权利。另外,你还没有向我们展示什么'ArrNames'被定义为。知道这将有所帮助。 – 2013-03-19 20:37:19