如何在 Delphi/FreePascal 中的函数内声明一个函数而不嵌套它们?
How can I declare a function from within a function in Delphi/FreePascal without nesting them?
我想做这样的事情:
(我想保留函数 public 以便我可以从其他 procedures/functions 访问它们)。
这些函数采用相同的形式 (frmSequenciador) - 我没有 post 因为它的完整性非常大..
function geradorDeVetores():TIntArray;
var
contador: Integer;
vetor: array [1..numMax] of integer;
begin
Randomize;
for contador:=1 to numMax do
begin
if contador = 1 then
vetor[contador]=float_round_down(Random*10);
else vetor[contador]:= ***frmSequenciador.evitaRepeticao(contador, vetor)***;
end;
end;
function evitaRepeticao(pos: integer; vetor:TIntArray):integer;
var
numigual: boolean;
temporario, cont: integer;
begin
numigual:=true;
temporario:= float_round_down(Random*10);
for cont:=1 to pos-1 do
if temporario <> vetor[cont] numigual:=false else numigual:=true;
if numigual=false then evitaRepeticao():=temporario else evitaRepeticao():=***frmSequenciador.evitaRepeticao(pos, vetor)***;
end;
如 Ken White 所述,删除函数的 frmSequenciador 前缀是一件简单的事情。
我想知道的是:如果两个函数在同一个表单单元中(thx Jerry),我们需要前缀才能相互调用吗?
好像没有。谢谢大家!
我想做这样的事情: (我想保留函数 public 以便我可以从其他 procedures/functions 访问它们)。 这些函数采用相同的形式 (frmSequenciador) - 我没有 post 因为它的完整性非常大..
function geradorDeVetores():TIntArray;
var
contador: Integer;
vetor: array [1..numMax] of integer;
begin
Randomize;
for contador:=1 to numMax do
begin
if contador = 1 then
vetor[contador]=float_round_down(Random*10);
else vetor[contador]:= ***frmSequenciador.evitaRepeticao(contador, vetor)***;
end;
end;
function evitaRepeticao(pos: integer; vetor:TIntArray):integer;
var
numigual: boolean;
temporario, cont: integer;
begin
numigual:=true;
temporario:= float_round_down(Random*10);
for cont:=1 to pos-1 do
if temporario <> vetor[cont] numigual:=false else numigual:=true;
if numigual=false then evitaRepeticao():=temporario else evitaRepeticao():=***frmSequenciador.evitaRepeticao(pos, vetor)***;
end;
如 Ken White 所述,删除函数的 frmSequenciador 前缀是一件简单的事情。
我想知道的是:如果两个函数在同一个表单单元中(thx Jerry),我们需要前缀才能相互调用吗? 好像没有。谢谢大家!