B
B
booomheadshot2014-03-20 22:06:39
Delphi
booomheadshot, 2014-03-20 22:06:39

Delphi. How to optimize the creation of records in the record class?

I need to implement the creation of records in a record in the most compact way, presumably using functions.
Tried like this:

The code
type
  TDrinker = record
    firstname: string;
    age: integer;
  end;

  TParty = class
    public
      function CreateDrinker(Drinker: TDrinker; fname: string; a: integer): string;

var
  Vasya: TDrinker;

  ........

  TParty.CreateDrinker(Drinker: TDrinker; fname: string; a: integer): string;
  begin
    with drinker do
      begin
        firstname:=fname;
        age:=a;
        result:='Создан участник '+firstname+' с возрастом '+age;
      end;
  end;

The bottom line is that when calling the CreateDrinker function with parameters - (Vasya, 'Vasya Pupkin', 21), the function should display in the Result information that the participant Vasya Pupkin, who is 21 years old, has been created.
Everything would be fine, but it is necessary that the Vasya entry is created, which is specified in the global var, and the Drinker entry is created, which is specified in the receiving parameters of the CreateDrinker function.
I tried to google, but I really can not formulate the problem, so I decided to turn here. Please help because it's important...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svd71, 2014-03-20
@booomheadshot

function CreateDrinker(var Drinker: TDrinker; fname: string; a: integer): string;

precede the parameter to be changed in the function, as var .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question