procedure SetInfo(MyObj:TObject; PropName: string; const Value: TValue); var PropKind:…
- User
procedure Set_Info(MyObj:TObject; PropName: string; const Value: TValue); var PropKind: TTypeKind; Ctx: TRttiContext; Field: TRttiField; begin Ctx := TRttiContext.Create; try Field := Ctx.GetType(MyObj.ClassType).GetField('F' + PropName); if Assigned(Field) then Field.SetValue(MyObj, Value) else raise Exception.Create('Error: Field "PropName + '" not found.'); finally // TRttiContext is a record; no need to free end; end;
procedure Set_Info_NullableDateTime(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
procedure Set_Info_NullableExtended(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
procedure Set_Info_NullableInteger(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
procedure Set_Info_NullableInt64(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
procedure Set_Info_NullableString(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
procedure Set_Info_NullableVariant(MyObj:TObject; PropName: string; const Value: TNullable); begin Set_Info(MyObj, PropName, TValue.From<TNullable>(Value)); end;
unit pixel_classes;
interface
uses System.SysUtils, Rtti, TypInfo;
{$TYPEINFO ON}
type TNullValue = record end;
TNullable<T{: record}> = record public Value: T; HasValue: Boolean;
codeclass operator Implicit(const AValue: T): TNullable<T>; class operator Implicit(const AValue: TNullable<T>): T; class operator Implicit(const AValue: TNullValue): TNullable<T>; class operator Explicit(const AValue: T): TNullable<T>; // add these... class operator Equal(const A: TNullable<T>; const B: TNullValue): Boolean; class operator NotEqual(const A: TNullable<T>; const B: TNullValue): Boolean;end;
var NullValue: TNullValue;
implementation
class operator TNullable.Implicit(const AValue: T): TNullable; begin Result.Value := AValue; Result.HasValue := True; end;
class operator TNullable.Implicit(const AValue: TNullable): T; begin if AValue.HasValue then Result := AValue.Value else Result := Default(T); // or raise an exception end;
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.