unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;type
TValue = Record
str1: string;
Int: integer;
str2: string;
str3: string;
End;
PValue = ^TValue;
AValue = Array Of PValue; TForm1 = class(TForm)
TreeView: TTreeView;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure AddArray(Var List: TList);
function GetValue: AValue;
public
{ Public declarations }
end;var
Form1: TForm1;
List: TList;implementation{$R *.dfm}procedure TForm1.AddArray(var List: TList);
Var
i: integer;
ArrayValue: Array Of PValue;
begin
SetLength(ArrayValue,4);
For i := 0 To 3 Do
Begin
New(ArrayValue[i]);
ArrayValue[i]^.str1 := 'aaa' + IntToStr(i);
ArrayValue[i]^.str2 := 'bbb' + IntToStr(i);
ArrayValue[i]^.str3 := 'ccc' + IntToStr(i);
End;
IF Assigned(List) Then List.Destroy;
IF Not Assigned(ArrayValue) Then Raise Exception.Create('Null of ArrayValue');
List := TList.Create;
List.Add(ArrayValue);
ShowMessage('The ArrayValue has Add into List Item');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AddArray(List);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
//
end;procedure TForm1.Button2Click(Sender: TObject);
Var
a: AValue;
i: integer;
begin
a := GetValue;
For i := Low(a) To High(a) Do
Begin
ShowMessage(a[i]^.str1);//这里取数据不出来,为什么?
End;
end;function TForm1.GetValue: AValue;
begin
Result := Nil;
IF Not Assigned(List) Then Exit;
Result := List.Items[0];
end;end.我把ArrayValue数组加到List中,然后通过GetValue取出来,但是取出来的没数据,为什么呢?谢谢!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;type
TValue = Record
str1: string;
Int: integer;
str2: string;
str3: string;
End;
PValue = ^TValue;
AValue = Array Of PValue; TForm1 = class(TForm)
TreeView: TTreeView;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure AddArray(Var List: TList);
function GetValue: AValue;
public
{ Public declarations }
end;var
Form1: TForm1;
List: TList;implementation{$R *.dfm}procedure TForm1.AddArray(var List: TList);
Var
i: integer;
ArrayValue: Array Of PValue;
begin
SetLength(ArrayValue,4);
For i := 0 To 3 Do
Begin
New(ArrayValue[i]);
ArrayValue[i]^.str1 := 'aaa' + IntToStr(i);
ArrayValue[i]^.str2 := 'bbb' + IntToStr(i);
ArrayValue[i]^.str3 := 'ccc' + IntToStr(i);
End;
IF Assigned(List) Then List.Destroy;
IF Not Assigned(ArrayValue) Then Raise Exception.Create('Null of ArrayValue');
List := TList.Create;
List.Add(ArrayValue);
ShowMessage('The ArrayValue has Add into List Item');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AddArray(List);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
//
end;procedure TForm1.Button2Click(Sender: TObject);
Var
a: AValue;
i: integer;
begin
a := GetValue;
For i := Low(a) To High(a) Do
Begin
ShowMessage(a[i]^.str1);//这里取数据不出来,为什么?
End;
end;function TForm1.GetValue: AValue;
begin
Result := Nil;
IF Not Assigned(List) Then Exit;
Result := List.Items[0];
end;end.我把ArrayValue数组加到List中,然后通过GetValue取出来,但是取出来的没数据,为什么呢?谢谢!
解决方案 »
- cxgrid打印用dxComponentPrinter的一个问题
- 参孝了很多资料也没弄懂DELPHI消息系统?有两个疑惑的地方不解,谢谢帮忙!
- 请教如何让DBGird的最后一行的结果为上面全部对应记录的和?
- 软件界面处理问题,急
- 《delphi5从入门到精通》和《delphi6从入门到精通》哪个好?
- delphi中怎样批量解压文件?
- 请教高手QUICKREPORT自定义预览窗口的问题。
- 简单问题:如何将表中某一字段的值添加在TreeView1的某一节点下?
- 关于Socket的OnRead事件
- *****很基本的asp问题,送分*****
- 除了摄像头,和采集卡,有没有USB式的摄像和电脑同步工作录像?
- DBGrid中如果判断重复记录的问题
定义成全局变量....
List中只能放指针,而你这里放的是一个动态数组,所以取不出来东西,给你修改一下:type
TValue = Record
str1: string;
Int: integer;
str2: string;
str3: string;
End;
PValue = ^TValue;
AValue = Array Of PValue;
PAValue=^AValue;///////////////定义一个指向AValue的指针
..............
private
procedure AddArray(Var List: TList);
function GetValue: PAValue;////////函数返回修改为一个PAValue指针
...........procedure TForm1.AddArray(var List: TList);
Var
i: integer;
PV:PAValue;
begin
new(PV);
SetLength(PV^,4);
For i := 0 To 3 Do
Begin
New(PV^[i]);
PV^[i]^.str1 := 'aaa' + IntToStr(i);
PV^[i]^.str2 := 'bbb' + IntToStr(i);
PV^[i]^.str3 := 'ccc' + IntToStr(i);
End;
List := TList.Create;
List.Add(PV);
end;..............
procedure TForm1.Button2Click(Sender: TObject);
Var
PV:PAValue;
i: integer;
begin
PV := GetValue;
ShowMessage(PV^[0]^.str1);//能够得到PV^[i]^.str1值
..............function TForm1.GetValue: PAValue;/////返回为PAValue
begin
Result := Nil;
..............
Result := List.Items[0];
end;
///这句话只执行完毕之后list仍然是空的...
for I:=0 to 3 do
list.Add(arrayvalue[I]);
这样为什么不行?
for I:=0 to 3 do
list.Add(arrayvalue[I]);
比如: IF Assigned(List) Then List.Destroy; 很少直接這樣寫的 雖然也沒錯我以前測試過
你把TList對象作為函數參數傳遞 然後在函數中.Add,到一定程度時會出錯的
应该是将一个数组做为一个元素放到List中。
那么说这样也行了
List.Add(@ArrayValue);
但是我这么做了之后,list还是()没有任何值添加进去了,可能真的如
beyondtkl(大龙驹<干掉小日本>) ( ) 信誉:116 所说
你把TList對象作為函數參數傳遞 然後在函數中.Add,到一定程度時會出錯的
真的是这样吗?
我的没有添加上...
这样也可以的。但 ArrayValue: Array Of PValue;要是全局变量才行。
然后取出的时候要function TForm1.GetValue: APValue;才行。因为List中的是指针。