请问delphi 中怎么把一个数组保存在一个控件中呢!!!

来源:百度知道 编辑:UC知道 时间:2024/05/22 21:12:47
您好,请问delphi怎么把一个数组保存在一个控件中呢 ,是用edit.text控件就可以保存吗,能不能把代码给我下下啊,我是初学者,不是很懂,谢谢各位哥哥姐姐了!!

任何开发语言,都不能把一个数组保存在一个控件中!因为不存入数据库或外部文件中,退出程序后,就消失。如果你的意思是把数组内容导入组件中,可以这样做:
窗体上有一个TListBox组件、一个按钮,将数组x的内容添加到TListBox组件中:
procedure TForm1.Button1Click(Sender: TObject);
var
x : array[1..15] of string;
i : integer;
begin
ListBox1.Clear;
for i:=1 to 15 do
begin
x [i] := inttostr(i);
ListBox1.Items.Add(x[i]);
end;
end;
------------------------------------------------
Unit1窗体源码:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.