P
pdrich
Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位,帮我改一下类赋值问题?小弟刚初学Delphi不久!
看有没有最佳这个类设计方法??
程序源代码:
unit uLossClass;
interface
uses
Windows;
type
TLoss = class
private
RatedCapacity: Single
//变压器额定容量 KVA
RatedHighVoltage: Single
//变压器额定高压电压 KV
RatedLowVoltage: Single
//额定低压电压 KV
RatedHighCurrent: Single
//额定高压电流 A
RatedLowCurrent: Single
//额定低压电流 A
ResistanceMeasureTemperature: Single
//电阻测量时温度
LoadMeasureTemperature: Single
//负载测量时温度
HighResistance_OA: Single
//高压电阻OA
HighResistance_OB: Single
//高压电阻OB
HighResistance_OC: Single
//高压电阻OC
LowResistance_ab: Single
//低压电阻ab
LowResistance_bc: Single
//低压电阻bc
LowResistance_ca: Single
//低压电阻ca
VoltageInductorMultiple: Integer
//电压互感器档位
CurrentInductorMultiple: Integer
//电流互感器档位
MeasureVoltage_AB: Single
//测量电压值AB
MeasureVoltage_BC: Single
//测量电压值BC
MeasureVoltage_CA: Single
//测量电压值CA
MeasureCurrent_A: Single
//测量电流值A
MeasureCurrent_B: Single
//测量电流值B
MeasureCurrent_C: Single
//测量电流值C
{fDate: TDateTime;
procedure SetDay(const Value: Integer);
procedure SetMonth(const Value: Integer);
procedure SetYear(const Value: Integer);
function GetDay: Integer;
function GetMonth: Integer;
function GetYear: Integer
}
public
function Loss_K: Single
// 计算负载K常数值函数
function ResistanceLoss_K: Single
// 计算K2常数值函数
procedure SetValue (K1, K2: Single);
{constructor Create
overload;
constructor Create (y, m, d: Integer)
overload;
procedure SetValue (y, m, d: Integer)
overload;
procedure SetValue (NewDate: TDateTime)
overload;
function LeapYear: Boolean;
procedure Increase (NumberOfDays: Integer = 1);
procedure Decrease (NumberOfDays: Integer = 1);
function GetText: string;
property Year: Integer read GetYear write SetYear;
property Month: Integer read GetMonth write SetMonth;
property Day: Integer read GetDay write SetDay;}
end;
implementation
{ TLoss }
{ TLoss }
function TLoss.Loss_K: Single
// 计算负载K常数值函数
begin
Result :=(235+75)/(235+LoadMeasureTemperature);
end;
function TLoss.ResistanceLoss_K: Single
// 计算K2常数值函数
begin
Result :=(235+LoadMeasureTemperature)/(235+ResistanceMeasureTemperature);
end;
procedure TLoss.SetValue(K1, K2: Single);
begin
ResistanceMeasureTemperature := K1;
LoadMeasureTemperature := K2;
end;
end.
---------------
unit LoadLossFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,uLossClass;
type
TFrmLoadLoss = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLoadLoss: TFrmLoadLoss;
implementation
{$R *.dfm}
procedure TFrmLoadLoss.Button1Click(Sender: TObject);
var
ADay: TLoss;
begin
// create an object
ADay:= TLoss.Create;
// use the object
ADay.SetValue (StrToFloat (Edit1.Text),StrToFloat (Edit2.Text) );
ShowMessage ('K2=' +FloatToStr(ADay.ResistanceLoss_K)+';K1='+FloatToStr(ADay.Loss_K));
end;
end.
看有没有最佳这个类设计方法??
程序源代码:
unit uLossClass;
interface
uses
Windows;
type
TLoss = class
private
RatedCapacity: Single
//变压器额定容量 KVA
RatedHighVoltage: Single
//变压器额定高压电压 KV
RatedLowVoltage: Single
//额定低压电压 KV
RatedHighCurrent: Single
//额定高压电流 A
RatedLowCurrent: Single
//额定低压电流 A
ResistanceMeasureTemperature: Single
//电阻测量时温度
LoadMeasureTemperature: Single
//负载测量时温度
HighResistance_OA: Single
//高压电阻OA
HighResistance_OB: Single
//高压电阻OB
HighResistance_OC: Single
//高压电阻OC
LowResistance_ab: Single
//低压电阻ab
LowResistance_bc: Single
//低压电阻bc
LowResistance_ca: Single
//低压电阻ca
VoltageInductorMultiple: Integer
//电压互感器档位
CurrentInductorMultiple: Integer
//电流互感器档位
MeasureVoltage_AB: Single
//测量电压值AB
MeasureVoltage_BC: Single
//测量电压值BC
MeasureVoltage_CA: Single
//测量电压值CA
MeasureCurrent_A: Single
//测量电流值A
MeasureCurrent_B: Single
//测量电流值B
MeasureCurrent_C: Single
//测量电流值C
{fDate: TDateTime;
procedure SetDay(const Value: Integer);
procedure SetMonth(const Value: Integer);
procedure SetYear(const Value: Integer);
function GetDay: Integer;
function GetMonth: Integer;
function GetYear: Integer
}
public
function Loss_K: Single
// 计算负载K常数值函数
function ResistanceLoss_K: Single
// 计算K2常数值函数
procedure SetValue (K1, K2: Single);
{constructor Create
overload;
constructor Create (y, m, d: Integer)
overload;
procedure SetValue (y, m, d: Integer)
overload;
procedure SetValue (NewDate: TDateTime)
overload;
function LeapYear: Boolean;
procedure Increase (NumberOfDays: Integer = 1);
procedure Decrease (NumberOfDays: Integer = 1);
function GetText: string;
property Year: Integer read GetYear write SetYear;
property Month: Integer read GetMonth write SetMonth;
property Day: Integer read GetDay write SetDay;}
end;
implementation
{ TLoss }
{ TLoss }
function TLoss.Loss_K: Single
// 计算负载K常数值函数
begin
Result :=(235+75)/(235+LoadMeasureTemperature);
end;
function TLoss.ResistanceLoss_K: Single
// 计算K2常数值函数
begin
Result :=(235+LoadMeasureTemperature)/(235+ResistanceMeasureTemperature);
end;
procedure TLoss.SetValue(K1, K2: Single);
begin
ResistanceMeasureTemperature := K1;
LoadMeasureTemperature := K2;
end;
end.
---------------
unit LoadLossFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,uLossClass;
type
TFrmLoadLoss = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLoadLoss: TFrmLoadLoss;
implementation
{$R *.dfm}
procedure TFrmLoadLoss.Button1Click(Sender: TObject);
var
ADay: TLoss;
begin
// create an object
ADay:= TLoss.Create;
// use the object
ADay.SetValue (StrToFloat (Edit1.Text),StrToFloat (Edit2.Text) );
ShowMessage ('K2=' +FloatToStr(ADay.ResistanceLoss_K)+';K1='+FloatToStr(ADay.Loss_K));
end;
end.