Home > Back-end >  [in] a novice, you see me what's the problem with this code
[in] a novice, you see me what's the problem with this code

Time:09-16

How can I let the class definition of variable UserName, in the process of SetValue can visit
The unit myclass.

Interface

Type
//define class
MyClassSample=class
UserName: string;
Age: Integer;
Procedure SetValue (UN: string; Age: Integer);

end;
Implementation
Procedure SetValue (UN: string; Age: Integer);
The begin
UserName:=UN;
Age:=age;
end;


End.

CodePudding user response:

 procedure SetValue (var A: MyClassSample; Un: string; Age: Integer); 
The begin
A.U serName:=UN;
A.a ge:=age;
end;

CodePudding user response:

Avoid variable constant, the same name in parameters, adding a type identifier is not confused since

Procedure SetValue (sUserName: string; Iage: Integer);

CodePudding user response:

Class variables, a class member function, you can access your code, SetValue statement belongs to a class member function, but to realize the function of a class member function, the compiler should go wrong,

 
The unit myclass.

Interface

Type
//define class
MyClassSample=class
UserName: string;
Age: Integer;
Procedure SetValue (UN: string; Age: Integer);

end;
Implementation
Procedure MyClassSample. SetValue (UN: string; Age: Integer);
The begin
UserName:=UN;
Age:=age;
end;
End.

CodePudding user response:

Correction, CSDN set the font is to code

 
The unit myclass.

Interface

Type
//define class
MyClassSample=class
UserName: string;
Age: Integer;
Procedure SetValue (UN: string; Age: Integer);

end;
Implementation
Procedure MyClassSample. SetValue (UN: string; Age: Integer);
The begin
UserName:=UN;
Age:=age;
end;
End.

CodePudding user response:

Instead of process procedure MyClassSample. SetValue (UN: string; Age: Integer);
  • Related