如何在下面的情況下測試一個非零TObject不包含特定類的對象?什麼時候在delphi中使用is運算符是正確的?
procedure TForm7.testme;
var
mystring: string;
obj: TObject;
begin
mystring := 'asd';
obj := TObject(mystring);
if assigned(obj) then
if obj is TestClass then // --> this is failing
// ...
end;
您可能來自另一種語言,其中字符串是對象。在Delphi中,一個字符串是**不是一個對象,所以你不應該將它轉換爲一個。 –
哦,'is'不是一個「命令」,它是一個操作符。 –