怎么才能讓類定義的變數UserName,在程序SetValue中可以訪問啊
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);
begin
UserName := un;
age := age;
end;
end.
uj5u.com熱心網友回復:
procedure SetValue(var A: MyClassSample;Un:string;age:Integer);
begin
A.UserName := un;
A.age := age;
end;
uj5u.com熱心網友回復:
避免變數常量同名,在引數前面加個型別標識,看以來不至于混淆procedure SetValue(sUserName:string;Iage:Integer);
uj5u.com熱心網友回復:
類成員函式,就可以訪問類變數,你的代碼,SetValue宣告 屬于類成員函式,但實作函式缺非類成員函式,編譯應該會出錯。
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);
begin
UserName := un;
age := age;
end;
end.
uj5u.com熱心網友回復:
更正下,csdn把字體設定也轉成代碼
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);
begin
UserName := un;
age := age;
end;
end.
uj5u.com熱心網友回復:
程序改為 procedure MyClassSample.SetValue(un:string;age:Integer);轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/41278.html
標籤:語言基礎/算法/系統設計
