我要对药品进行一些统计,定义了如下的记录:
type
CDrug=record
PriceID:string;
ProductName:string;
Price:real;
MediType:integer;
end;
其中MediType属性是药品的类型,它是根据ProductName中是否包含某个特定的字符来定的:如果最左边的字符是*,则MediType:=1;是&,则MediType:=2;是^则MediType:=3;
好象在record中是不能写过程的,如果将CDrug写成对象(CLASS),这个获得MediType的值的过程又如何写呢?还有就是究竟写成记录还是对象好一些呢?
type
CDrug=record
PriceID:string;
ProductName:string;
Price:real;
MediType:integer;
end;
其中MediType属性是药品的类型,它是根据ProductName中是否包含某个特定的字符来定的:如果最左边的字符是*,则MediType:=1;是&,则MediType:=2;是^则MediType:=3;
好象在record中是不能写过程的,如果将CDrug写成对象(CLASS),这个获得MediType的值的过程又如何写呢?还有就是究竟写成记录还是对象好一些呢?
比如type
CDrug = class
private
FPriceID:string;
FProductName:string;
FPrice:real;
FMediType:integer;
private
procedure SetProductName(const Value: string);
public
property ProductName read FProductName Write SetProductName;
end; procedure CDrug.SetProductName(const Value: string);
begin
FProductName := Value;
if Value <> '' then
begin
if Value[1] = '*' then
FMediType := 1;
....
end;
end;或者里面用 case.... ps. 楼主 搞VC的么?
谢谢指点,我试一下。
PS. 我不是vc的,其实是搞管理,只是喜欢编程,有时做点小项目混一下见笑了:)
property ProductName:string read FProductName Write SetProductName;