所有,
在Delphi中,我创建了一个名为T_Test的简单类(请参见下文)。
T_Test = class(TObject)
private
F_Int : Integer;
public
constructor Create(inInt: Integer);
destructor Destroy; override;
property Int: Integer read F_Int write F_Int;
function showInt : String;
end;
constructor T_Test.Create(inInt: Integer);
begin
F_Int := inInt;
end;
destructor T_Test.Destroy;
begin
self.Free;
end;
function T_Test.showInt : String;
var outputLine : String;
begin
result := IntToStr(Int);
outputLine := result;
Form1.Memo1.Lines.Add(outputLine);
end;
然后我有一个过程,要在其中创建T_Test对象的TList并调用
showInt方法函数在它们上面。
我这样尝试过:
procedure testTlist;
var
a, b: T_Test;
i : Integer;
begin
a := T_Test.Create(5);
b := T_Test.Create(10);
listTest := TList.Create;
listTest.Add(a);
listTest.Add(b);
listTest[i].showInt;
end;
但是我一直收到一个提示,说我必须在记录上使用Record,Object或Class Type。
“ listTest [i] .showInt”的调用
有人知道如何调用此方法吗?
最佳答案
将listTest [i]指针转换回T_Test,然后调用其方法:
T_Test(listTest[i]).showInt;
或者,如果可用,请使用模板化的TObjectList类直接存储T_Test实例。
关于delphi - delphi tlist对象方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12017188/