Главная страница | назад





Article #23006: Passing nil to a variable parameter.

QUESTION:

How do I pass nil to a variable parameter of a method?

ANSWER:

Create the pointer type, assign it nil and pass it in by dereferencing it.

var
value: PInt;
begin
value := nil;
NextVal(value^);
end;

Now to use the passed in parameter you will have to check for nil first by getting the address of the Integer.
function NextVal(var value: Integer): HResult; stdcall;
begin
if @value <> nil then
ShowMessage('value ' + IntToStr(value))
else
ShowMessage('passed nil');
Result := 0;
end;

Last Modified: 15-SEP-00