S
szsunboy
Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾看一下下面我所定的类:
1.我想在创建时,输入两个参数:FileName、FieldNo(现在只让我输入一下)
2.我想在类创建时,就自动设置其中的属性值
如果您能将我的类完整地改写一下,并发给我(newemail@163.net),让本人来认真学习一下,我将不胜感激!
另外:
这个类是要实现这样的一个功能:
从.ini文件里面读到一个Person定义(根据No),并给其赋初值
文件格式为:
[111]
NAME=Tom
SEX=F
AGE=10
以下是我的类:
---------------------------------------------------------------
unit PersonDef;
interface
uses
Classes, SysUtils, Windows, IniFiles, Forms;
type
TPerson = Class(TIniFile)
private
fNo: Integer;
function GetName: Variant;
function GetSex: String;
function GetAge: String;
protected
constructor Create(const No: Integer
FileName: String);override;
destructor Destroy;
public
property Name: String Read GetName;
property Sex: String Read GetSex;
property Age: Integer Read GetAge;
end;
implementation
constructor Create(const No: Integer
FileName: String);override;
begin
fNo := 0;
inherited Create(FileName);
end;
destructor Destroy;
begin
inherited Destory;
end;
function TPerson.GetName: Variant;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'NAME', '');
end;
function TPerson.GetSex: String;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'SEX', '');
end;
function TPerson.GetAge: Integer;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'AGE', 'C');
end;
end.
1.我想在创建时,输入两个参数:FileName、FieldNo(现在只让我输入一下)
2.我想在类创建时,就自动设置其中的属性值
如果您能将我的类完整地改写一下,并发给我(newemail@163.net),让本人来认真学习一下,我将不胜感激!
另外:
这个类是要实现这样的一个功能:
从.ini文件里面读到一个Person定义(根据No),并给其赋初值
文件格式为:
[111]
NAME=Tom
SEX=F
AGE=10
以下是我的类:
---------------------------------------------------------------
unit PersonDef;
interface
uses
Classes, SysUtils, Windows, IniFiles, Forms;
type
TPerson = Class(TIniFile)
private
fNo: Integer;
function GetName: Variant;
function GetSex: String;
function GetAge: String;
protected
constructor Create(const No: Integer
FileName: String);override;
destructor Destroy;
public
property Name: String Read GetName;
property Sex: String Read GetSex;
property Age: Integer Read GetAge;
end;
implementation
constructor Create(const No: Integer
FileName: String);override;
begin
fNo := 0;
inherited Create(FileName);
end;
destructor Destroy;
begin
inherited Destory;
end;
function TPerson.GetName: Variant;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'NAME', '');
end;
function TPerson.GetSex: String;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'SEX', '');
end;
function TPerson.GetAge: Integer;
var
SecName: String;
begin
SecName := Format('%.3d', [fNo]);
Result := ReadString(SecName, 'AGE', 'C');
end;
end.