在Delphi中,Assigned函数用于检查指定的引用是否已经分配了内存。它通常用于检查对象引用是否为空。Assigned函数的语法如下:
function Assigned(Obj: TObject): Boolean;
示例用法如下:
var MyObject: TObject; begin MyObject := TObject.Create; if Assigned(MyObject) then ShowMessage('MyObject has been allocated'); else ShowMessage('MyObject has not been allocated'); end;
在以上示例中,我们首先创建了一个TObject类型的对象MyObject,并使用Assigned函数检查该对象是否已经分配了内存。如果对象已经被分配了内存,则显示’MyObject has been allocated’,否则显示’MyObject has not been allocated’。