Thursday, 15 January 2015

How can I make a TDate parameter optional in Delphi? -



How can I make a TDate parameter optional in Delphi? -

my class looks this;

type tbatchfilter = class(tobject) private fbatchno: string; fline: string; fcutoffdate: tdate; public constructor create(abatchno, aline: string; acutoffdate: tdate); overload; constructor create(abatchfilter: tbatchfilter); overload; property batchno: string read fbatchno; property line: string read fline; property cutoffdate: tdate read fcutoffdate; end;

i want create acutoffdate:tdate parameter optional. thing of calling constructor this;

mybatchfilter := tbatchfilter('batch1', 'line1', nil);

then in constructor have this;

if (acuttoffdate = nil) dosomething else dosomethingelse;

but can't pass nil parameter. don't want overload constructor further.

there 2 obvious ways tackle this:

add overloaded constructor omits date parameter. make date parameter have default value sentinel value has no meaning.

you've attempted utilize nil sentinel, sentinel has valid value type. , nil not. you'll need pick suitable value. perhaps zero. or big positive or negative value. whatever choose, declare named constant give code semantic clarity.

delphi parameters

No comments:

Post a Comment