이 (코드 구문 설명 참조) 작품 :
Type
TRec = record
s: string;
p: procedure; // As Ken pointed out, better define a procedural type:
// type TMyProc = procedure; and declare p : TMyProc;
end;
procedure run; forward; // The forward is needed here.
// If the procedure run was declared in the interface
// section of a unit, the forward directive should not be here.
Const
Rec: TRec = (s:''; p:run); // The const record is predefined by the compiler.
procedure run;
begin
WriteLn('Test');
end;
begin
Rec.p; // Rec.run will not work since run is not a declared member of TRec.
// The array index (Rec[0]) is not applicable here since Rec is not declared as an array.
ReadLn;
end.
을이 좋은 반면,이 질문을 받았다없는거야. 포스터는'Rec.p'에'procedure run'을 할당하고'Rec.run'을 사용할 수 있는지 물어 봤습니다 - 당신의 코드는'Rec.p '를 사용하여 보여 줍니 다. . –
@KenWhite, 네가 맞을지도 모르지만 내 예제에서는 const 레코드를 통해 OP 실행 프로 시저를 호출하게한다. Rec. –
맞습니다.하지만 물어 보지 않은 것은 "나중에 실행할 수 있습니다 : Rec [0] .run;"이며 * 불가능 *합니다. :) 아무리해도 - OP는 솔루션이 작동한다고 생각하는 것 같습니다. (내 대답을 삭제하고 자신을 업 그레 이드) –