フォーラム


ゲスト  

ようこそ ゲスト さん。このフォーラムに投稿するには 登録が必要です。

ページ: [1]
トピック: TCustomEdit 用のクラスヘルパー
DEKO
管理者
投稿数: 2690
TCustomEdit 用のクラスヘルパー
on: 2014/04/23 20:05 Wed

業務アプリで、TEdit (またはそれの類似コンポーネント) に値を入れたり出したりするのがメンドイ時に使います。StrToInt() / IntToStr() 等の変換関数をその都度噛ますのがメンドイというモノグサなヒト向けの手法です。

TCustomEdit のクラスヘルパーですから、TEdit だけでなく、TMaskEdit 等にも AsInteger 等のプロパティが追加されます…ただ、やりたい事 (変換のルール) はヒトによって異なるでしょうから、自由に改変して使ってください。

[uCustomEditHelper ver 1.00]
http://ht-deko.minim.ne.jp/software/customedithelper_100.zip

使い方は uCustomEditHelper を uses するだけです。そうすると、Edit1.AsInteger とかで値を出し入れできます。

type
{ TCustomEditExtention }
TCustomEditExtention =
class helper for TCustomEdit
private
// Access Methods
function GetBoolean: Boolean;
function GetCurrency: Currency;
function GetDate: TDate;
function GetDateTime: TDateTime;
function GetFloat: Double;
function GetInt64: Int64;
function GetInteger: Integer;
function GetString: string;
function GetTime: TTime;
procedure SetBoolean(const Value: Boolean);
procedure SetCurrency(const Value: Currency);
procedure SetDate(const Value: TDate);
procedure SetDateTime(const Value: TDateTime);
procedure SetFloat(const Value: Double);
procedure SetInt64(const Value: Int64);
procedure SetInteger(const Value: Integer);
procedure SetString(const Value: string);
procedure SetTime(const Value: TTime);
public
// Methods
function IsDateStr: Boolean; // Text が日付文字列として正しいかどうかを判定する
function IsDateTimeStr: Boolean; // Text が日付時刻文字列として正しいかどうかを判定する
function IsEmpty: Boolean; // Text が空文字列であるか判定する
function IsEmptyMaskStr: Boolean; // Text が空のマスク文字列であるかを判定する
function IsTimeStr: Boolean; // Text が時刻文字列として正しいかどうかを判定する
procedure SetMaskStr(MaskType: TMaskType); // マスク文字列を設定する
procedure ToLower; // Text を大文字に変換する
procedure ToTrimStr; // Text の前後空白文字を取り除く
procedure ToUpper; // Text を小文字に変換する
published
// Properties
property AsBoolean: Boolean read GetBoolean write SetBoolean; // Text を Boolean 型として扱う
property AsCurrency: Currency read GetCurrency write SetCurrency; // Text を Currency 型として扱う
property AsDate: TDate read GetDate write SetDate; // Text を TDate 型として扱う
property AsDateTime: TDateTime read GetDateTime write SetDateTime; // Text を TDateTime 型として扱う
property AsFloat: Double read GetFloat write SetFloat; // Text を Double 型として扱う
property AsInt64: Int64 read GetInt64 write SetInt64; // Text を Int64 型として扱う
property AsInteger: Integer read GetInteger write SetInteger; // Text を Integer 型として扱う
property AsString: string read GetString write SetString; // Text を String 型として扱う
property AsTime: TTime read GetTime write SetTime; // Text を TTime 型として扱う
end;

 
ヘッダを貼っておきますね。

ページ: [1]
WP Forum Server by ForumPress | LucidCrew
バージョン: 1.7.5 ; ページロード: 0.034 sec.