📄 gsentityfield.pas
字号:
unit gsEntityField;
(******************************************************************
封装实体字段类型
Copyright (c) 2005 by TinTin.
Author : TinTin
Date : 2006.07
******************************************************************)
interface
uses
SysUtils,Classes, DB, TypInfo, Contnrs, Variants;
const
cstWrap = #13#10;
type
//实体字段类
TMPropFieldClass = class of TgsPropField;
TgsPropField = class(TPersistent)
private
FCaption: string;
FName: string;
procedure SetCaption(const Value: string);
procedure SetName(const Value: string);
published
property Name: string read FName write SetName;
property Caption: string read FCaption write SetCaption;
end;
//默认有六个实体字段类
TIntF = class(TgsPropField)
private
FValue: Integer;
procedure SetValue(Value: Integer);
function GetStrValue: string;
published
property Name;
property Caption;
property AsInt: Integer read FValue write SetValue;
property ToStr: string read GetStrValue;
end;
TNumberF = class(TgsPropField)
private
FValue: Double;
procedure SetValue(const Value: Double);
function GetStrValue: string;
published
property Name;
property Caption;
property AsNum: Double read FValue write SetValue;
property ToStr: string read GetStrValue;
end;
TStringF = class(TgsPropField)
private
FValue: Widestring;
procedure SetValue(const Value: Widestring);
published
property Name;
property Caption;
property AsStr: Widestring read FValue write SetValue;
end;
TDateTimeF = class(TgsPropField)
private
FValue: TDateTime;
procedure SetValue(const Value: TDateTime);
function GetDateTimeValue: string;
function GetDateValue: string;
function GetTimeValue: string;
published
property Name;
property Caption;
property AsDT: TDateTime read FValue write SetValue;
property ToDateTimeStr: string read GetDateTimeValue;
property ToDateStr: string read GetDateValue;
property ToTimeStr: string read GetTimeValue;
end;
TBooleanF = class(TgsPropField)
private
FValue: Boolean;
procedure SetValue(const Value: Boolean);
function GetStrValue: string;
published
property Name;
property Caption;
property AsBool: Boolean read FValue write SetValue;
property ToStr: string read GetStrValue;
end;
TVarF = class(TgsPropField)
private
FValue: Variant;
procedure SetValue(const Value: Variant);
function GetStrValue: string;
published
property Name;
property Caption;
property AsVar: Variant read FValue write SetValue;
property ToStr: string read GetStrValue;
end;
TBlobF = class(TgsPropField)
private
FValue: TStream;
procedure SetValue(const Value: TStream);
published
property Name;
property Caption;
property AsBlob: TStream read FValue write SetValue;
end;
implementation
uses Dialogs;
{ TgsPropField }
procedure TgsPropField.SetCaption(const Value: string);
begin
FCaption := Value;
end;
procedure TgsPropField.SetName(const Value: string);
begin
FName := Value;
end;
function TIntF.GetStrValue: string;
begin
Result := IntToStr(FValue);
end;
procedure TIntF.SetValue(Value: Integer);
begin
if FValue <> Value then
FValue := Value;
end;
{ TBooleanF }
function TBooleanF.GetStrValue: string;
begin
Result := BoolToStr(FValue);
end;
procedure TBooleanF.SetValue(const Value: Boolean);
begin
FValue := Value;
end;
{ TDoubleF }
function TNumberF.GetStrValue: string;
begin
Result := FloatToStr(FValue);
end;
procedure TNumberF.SetValue(const Value: Double);
begin
FValue := Value;
end;
{ TStringF }
procedure TStringF.SetValue(const Value: Widestring);
begin
FValue := Value;
end;
{ TDateTimeF }
function TDateTimeF.GetDateTimeValue: string;
begin
Result := FormatDateTime('yyyy-MM-dd HH:NN:SS', FValue);
end;
function TDateTimeF.GetDateValue: string;
begin
Result := FormatDateTime('yyyy-MM-dd', FValue);
end;
function TDateTimeF.GetTimeValue: string;
begin
Result := FormatDateTime('HH:NN:SS', FValue);
end;
procedure TDateTimeF.SetValue(const Value: TDateTime);
begin
FValue := Value;
end;
procedure TBlobF.SetValue(const Value: TStream);
begin
FValue := Value;
end;
{ TVarF }
function TVarF.GetStrValue: string;
begin
if VarIsEmpty(FValue) then
Result :=''
else
Result := VarToStr(FValue);
end;
procedure TVarF.SetValue(const Value: Variant);
begin
FValue := Value;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -