Jump to content
pcoder

alternative to call parameter?

Recommended Posts

procedure TObj.run;
var r: TRecord;
begin
...; processRecord( r); ...;
end;

ProcessRecord is a method and contains many nested calls (more methods).
The issue is that many methods would need an additional parameter (very cumbersome).
Therefore an alternative is wanted. Object-field FR (PRecord) is a pointer (rather than record) to reduce memory outside of runs.

is there any preference for one of them?

procedure TObj.run2;
begin
  new( FR); 
  ...; processRecord; ...;
  dispose(FR);
  FR := nil;
end;
procedure TObj.run3;
var r: TRecord;
begin
  FR := @r; 
  ...; processRecord; ...; 
  FR := nil;
end;

 

Share this post


Link to post

I would choose the latter. No need to allocate memory dynamically unless the record instance needs to live after TObj.run3() exits. 

 

But, if you have a lot of methods of TObj that are acting on the record then they should instead be methods of TRecord itself. Consider refactoring your code to make it cleaner.

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×