[lazarus] dealing with objects' properties
Michael Van Canneyt
michael.vancanneyt at wisa.be
Tue May 2 10:43:10 EDT 2000
On Tue, 2 May 2000, dvortex wrote:
>
> I was waking up this morning after a short night of sleep, and i realized
> that maybe i should modify the TObject code and add this:
>
> Procedure TObject.SetProperty(PropertyName).AsString
> .AsFloat
> .AsInteger
>
> (How can i code something like this by the way ?)
>
> and maybe
> Function TObject.GetPropertList : TStringList;
>
> ?
>
> What do you think ?
> that would allow to make component coding a lot easier, don't you think ?
And it would increase all existing code unnecessary much because it is in
the system unit, so better not in the system unit.
Not to mention that you would need the typinfo unit in the system unit, which
would introduce a circular unit dependency. The alternative, to 'include' the
typinfo in the system unit, is definitely out of the question.
You CAN insert it in the typinfo unit, however:
Delphi 5 has similar procedures in it's typinfo unit, which we didn't
implement yet. If you implement it there, I will include it in the RTL:
Here is the list of functions. The Get/Set functions do what you want to
do.
A sample implementation would be:
procedure SetStrProp(Instance: TObject;
Const PropName: String;
Const Value: String);
begin
SetStrProp(Instance,GetPropInfo(Instance, PropName),Value);
end;
function IsPublishedProp(Instance: TObject; const PropName: string): Boolean; overload;
function IsPublishedProp(AClass: TClass; const PropName: string): Boolean; overload;
function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds = []): PPropInfo; overload;
function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds = []): PPropInfo; overload;
function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean; overload;
function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean; overload;
function PropType(Instance: TObject; const PropName: string): TTypeKind; overload;
function PropType(AClass: TClass; const PropName: string): TTypeKind; overload;
function IsStoredProp(Instance: TObject; const PropName: string): Boolean; overload;
function GetOrdProp(Instance: TObject; const PropName: string): Longint; overload;
procedure SetOrdProp(Instance: TObject; const PropName: string;
Value: Longint); overload;
function GetEnumProp(Instance: TObject; const PropName: string): string; overload;
procedure SetEnumProp(Instance: TObject; const PropName: string;
const Value: string); overload;
function GetSetProp(Instance: TObject; const PropName: string;
Brackets: Boolean = False): string; overload;
procedure SetSetProp(Instance: TObject; const PropName: string;
const Value: string); overload;
function GetObjectProp(Instance: TObject; const PropName: string;
MinClass: TClass = nil): TObject; overload;
procedure SetObjectProp(Instance: TObject; const PropName: string;
Value: TObject); overload;
function GetObjectPropClass(Instance: TObject; const PropName: string): TClass; overload;
function GetStrProp(Instance: TObject; const PropName: string): string; overload;
procedure SetStrProp(Instance: TObject; const PropName: string;
const Value: string); overload;
function GetFloatProp(Instance: TObject; const PropName: string): Extended; overload;
procedure SetFloatProp(Instance: TObject; const PropName: string;
Value: Extended); overload;
function GetVariantProp(Instance: TObject; const PropName: string): Variant; overload;
procedure SetVariantProp(Instance: TObject; const PropName: string;
const Value: Variant); overload;
function GetMethodProp(Instance: TObject; const PropName: string): TMethod; overload;
procedure SetMethodProp(Instance: TObject; const PropName: string;
const Value: TMethod); overload;
function GetInt64Prop(Instance: TObject; const PropName: string): Int64; overload;
procedure SetInt64Prop(Instance: TObject; const PropName: string;
const Value: Int64); overload;
function GetPropValue(Instance: TObject; const PropName: string;
PreferStrings: Boolean = True): Variant;
procedure SetPropValue(Instance: TObject; const PropName: string;
const Value: Variant);
Michael.
More information about the Lazarus
mailing list