>>
LPARAMETERS toObj
>>IF PEMSTATUS(toObj, "oGadget", 5)
>> toObj.oengine=this.oGadget
>>ENDIF
public void Doit(object toObj)
> {
> PropertyInfo pi = toObj.GetType().GetProperty("oengine");
> if (pi != null)
> pi.SetValue(toObj,oGadget,null);
> }
>
Interesting separation... a property is an object, still related to its owner but you can operate on it all the same. A tad more complicated, but as long as it gets the job done, cool.
What's the null in the last line for? And, oGadget isn't defined... shouldn't it be a string literal?
>>
LPARAMETERS toObj
>> IF toObj.BASECLASS="Timer"
>> IF toObj.ENABLED AND toobj.interval>0
>> toObj.ENABLED=.F.
>> toObj.INTERVAL=0
>> ENDIF
>> ENDIF
>>
public void Doit (object toObj)
> {
> Timer t = toObj as Timer;
> if (t != null)
> {
> if (t.Enabled
> {
> t.Enabled = false;
> t.Interval = 0;
> }
> }
> }
The AS operator is unintuitive but neat... implicit cast returning a null if it fails? Though, this sounds more like a try-catch "see if this works" code, instead of having an IsA(toObj, tcClass) function. What happens if you try to cast a twice subclassed timer as a timer, do you still get a reference to the original object?
>I'd do a bit more type checking in the first one if it was for production - but even as it stands it is safer than the VFP version...
And what's unsafe in it?