相关疑难解决方法(0)

Delphi:函数结果在for循环期间没有清空

这是正常的吗?

for a := 1 to 10 do
    x.test;

   x.test;
   x.test;
   x.test;

function test: string;
begin
  {$IFDEF DEBUG}  DebugMessage('result check = '+Result,3); {$ENDIF}
   result := result + 'a';
end;

10:39:59: result check = 
10:39:59: result check = a
10:39:59: result check = aa
10:39:59: result check = aaa
10:39:59: result check = aaaa
10:39:59: result check = aaaaa
10:39:59: result check = aaaaaa
10:39:59: result check = aaaaaaa
10:39:59: result check = aaaaaaaa
10:39:59: result check = aaaaaaaaa

10:39:59: result …
Run Code Online (Sandbox Code Playgroud)

delphi stack function

5
推荐指数
2
解决办法
422
查看次数

记录中的接口字段

我可以依赖这样一个事实,即记录中的接口字段是否始终初始化为nil

TMyRec = record  
  FGuard : IInterface;
  FObject : TObject;
  procedure CheckCreated;
end;
Run Code Online (Sandbox Code Playgroud)

这将允许我写:

procedure TMyCheck.CheckCreated;
begin
if (FGuard = nil) then
  begin
  FObject := TObject.Create;
  FGuard := TGuard.Create (FObject);
  end;
end;
Run Code Online (Sandbox Code Playgroud)

(用于自动终身管理)

我知道接口字段已初始化为,nil但是当包含在记录中时也是如此?

delphi delphi-xe

3
推荐指数
1
解决办法
688
查看次数

标签 统计

delphi ×2

delphi-xe ×1

function ×1

stack ×1