Re:(dis)advantages of 'with'?
Quote
Stefan Hoffmeister wrote:
> >I found 'with' not working with some array types (of records), and therefore
> >would like to know more about the 'with' statement.
> It always works.
I'd hate to disagree... because it really depends on one's definition of
"works". However, I find it slightly annoying that I have to write:
procedure TNCCSGBranch.Assign(Source:TPersistent);
var
SourceClass:TNetworkClass;
begin
if Assigned(Source) and (Source is TNCCSGBranch) then
begin
FLeftNode.Free;
FLeftNode:=nil;
if Assigned((Source as TNCCSGBranch).FLeftNode) then
begin
SourceClass:=TNetworkClass((Source as
TNCCSGBranch).FLeftNode.ClassType);
FLeftNode:=(SourceClass.Create as TNCCSGNode);
FLeftNode.Assign((Source as TNCCSGBranch).FLeftNode);
end;
end;
inherited Assign(Source);
end;
rather than something like:
procedure TNCCSGBranch.Assign(Source:TPersistent);
var
SourceClass:TNetworkClass;
begin
if Assigned(Source) and (Source is TNCCSGBranch) then
begin
with (Source as TNCCSGBranch) do
begin
Self.FLeftNode.Free;
Self.FLeftNode:=nil;
if Assigned(FLeftNode) then
begin
SourceClass:=TNetworkClass(FLeftNode.ClassType);
Self.FLeftNode:=(SourceClass.Create as TNCCSGNode);
Self.FLeftNode.Assign(FLeftNode);
end;
end;
end;
inherited Assign(Source);
end;
If you get my general drift.
Basically, I just wish the with statement would let one mask the
implicit "self" in all field and method declarations, instead making
them apply to a checked typecast of another object...
Wierd, and perhaps not very good for the novice programmer, but it would
have saved me a lot of typing over the past few months!
MH.
--
Martin Harvey.
http://www.harvey27.demon.co.uk/mch24/
PGP key available from above address,
or http://wwwkeys.pgp.net/