在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’。