相关疑难解决方法(0)

在Delphi中声明本地或全球?

我有一个程序,我的程序调用数万次,使用这样的通用结构:

procedure PrintIndiEntry(JumpID: string);

type
  TPeopleIncluded = record
    IndiPtr: pointer;
    Relationship: string;
  end;

var
  PeopleIncluded: TList<TPeopleIncluded>;
  PI: TPeopleIncluded;

begin { PrintIndiEntry }

  PeopleIncluded := TList<TPeopleIncluded>.Create;

 { A loop here that determines a small number (up to 100) people to process }
  while ... do begin

    PI.IndiPtr := ...;
    PI.Relationship := ...;
    PeopleIncluded.Add(PI);

  end;

  DoSomeProcess(PeopleIncluded);

  PeopleIncluded.Clear;
  PeopleIncluded.Free;

end { PrintIndiEntry }
Run Code Online (Sandbox Code Playgroud)

或者,我可以在全局而不是本地声明PeopleIncluded,如下所示:

unit process;

interface

type
  TPeopleIncluded = record
    IndiPtr: pointer;
    Relationship: string;
  end;

var
  PeopleIncluded: TList<TPeopleIncluded>;
  PI: TPeopleIncluded;

procedure PrintIndiEntry(JumpID: …
Run Code Online (Sandbox Code Playgroud)

delphi scope global-variables local-variables

0
推荐指数
1
解决办法
1385
查看次数

标签 统计

delphi ×1

global-variables ×1

local-variables ×1

scope ×1