Delphi Firemonkey get/set TBitmap through RTTI

  

How can I get/set TBitmap through RTTI? I have done as following:

function TMyWebCam.BitmapToString: string;
var
RContext : TRttiContext;
RType: TRttiType;
prop: TRttiProperty;
value : TValue;
begin
RContext := TRttiContext.Create;
RType := RContext.GetType(ClassType);
prop := RType.GetProperty(‘screenshot’);
prop.GetValue(Self).TryCast(TypeInfo(TBitmap), value);
Result := value.ToString;
end;

which gives me: (TBitmapOfItem @ 07A06280)
For converting string to TBitmap have done as following:

procedure TMyWebCam.SetScreenshot(AString: String);
var
RContext : TRttiContext;
RType: TRttiType;
prop: TRttiProperty;
value : TValue;
begin
RContext := TRttiContext.Create;
RType := RContext.GetType(ClassType);
prop := RType.GetProperty(‘screenshot’);
value.Cast(TypeInfo(TBitmap));
value.From<String>(AString);
prop.SetValue(Self, value);
end;

This is my class

TMyWebCam = class
private
fscreenshot: TBitmap;
public
constructor Create;
destructor Destroy;override;
property screenshot: TBitmap read fscreenshot write fscreenshot;
function BitmapToString : string;
procedure SetScreenshot(AString : String);
end;

constructor TMyWebCam.Create;
begin
fscreenshot := TBitmap.Create;
end;

destructor TMyWebCam.Destroy;
begin
fscreenshot.Free;
inherited;
end;

I have to convert TBitmap to string for passing it to another client as Broadcast message.

Comments are closed.