Menu

#1 Change the NewForm??? function to allow easy extension

open
nobody
5
2008-11-10
2008-11-10
Anonymous
No

To allow easy extension of kol-mck objects I use this:

procedure New{ObjectName}(var Result: P{ObjectName}; AParent: PControl; inheriting : Boolean = false);
begin
if not inheriting then
begin
{$IFDEF KOLCLASSES}

Result := P{ObjectName}.Create;

{$ELSE OBJECTS}

New( Result, Create );

{$ENDIF KOL CLASSES/OBJECTS}

end;

end;
...
end;

It doesn't break any existing software and allow extension as easy as this;

TMyControl = TControl
fNewMember : integer;
preocedure doSomething;
end;

procedure NewMyControl(var Result; AParent: PControl; inheriting=false);
begin
New(Result, Create);
NewControl(Result,AParent,true);
fNewMember := 33;
...
end;

On mirror.pas of mck :
SL.Add( 'procedure New' + FormName + '( var Result: P' + FormName +

'; AParent: PControl; inheriting: boolean = false );' );

SL.Add( 'begin' );

SL.Add( '' );

SL.Add( ' if not inheriting then' );

SL.Add( ' begin' );

SL.Add( ' {$IFDEF KOLCLASSES}' );

SL.Add( ' Result := P' + FormName + '.Create;' );

SL.Add( ' {$ELSE OBJECTS}' );

SL.Add( ' New( Result, Create );' );

SL.Add( ' {$ENDIF KOL CLASSES/OBJECTS}' );

SL.Add( ' end;' );

Discussion


Log in to post a comment.