Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi Firemonkey get/set TBitmap through RTTI


This question is answered.


Permlink Replies: 2 - Last Post: May 31, 2016 12:29 PM Last Post By: Remy Lebeau (Te...
Md. Shariful Al...

Posts: 70
Registered: 9/9/01
Delphi Firemonkey get/set TBitmap through RTTI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 29, 2016 1:03 PM
I am trying to broadcast peer-to-peer through DataSnap REST server Live webcamera. For this I made following class:
TMyWebCam = class
private
fscreenshot: TBitmap;
public
constructor Create;
destructor Destroy;override;
property screenshot: TBitmap read fscreenshot write fscreenshot;
function BitmapToString : string;//for setting by the sender client who start webcamera
procedure SetScreenshot(AString : String);//for getting from sender to set screenshot by reciving client in a TImage
end;

//to get string from screenshot property
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;

//to set screenshot property after broadcast
//this method is not working.
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.AsClass);
end;

Also I tried to do TDSAdminClient BroadcastObjectToChannel method to broadcast TMyWebCam as following:
var
AClient: TDSAdminClient;
begin
AClient := TDSAdminClient.Create(ServerConnection.DBXConnection);
Result := AClient.BroadcastObjectToChannel('crownim', MyWebCam);//MyWebCam initialize by the sender & receiver and sender fill the screenshot from TImage
end;

I am getting AV as "Internal: Type tkInterface is not currently supported".

How to solve those 2 issues?
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Delphi Firemonkey get/set TBitmap through RTTI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2016 9:30 AM   in response to: Md. Shariful Al... in response to: Md. Shariful Al...
Md. Shariful Alam Khan wrote:

[snip]

The Bitmap is a class and cannot convert it using the value.ToString.
Also note that the bitmap is not a string.

The Bitmap has a SaveToStream method. Call this to gain a stream that
you can send over the network and call LoadFromStream on the other hand
to set the bitmap. That's the fastest way.

Of course you can encode the bytes of the stream to a string, send that
string over the network and decode the string back to the stream on the
other end.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi Firemonkey get/set TBitmap through RTTI
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2016 12:29 PM   in response to: Md. Shariful Al... in response to: Md. Shariful Al...
Md. Shariful Alam Khan wrote:

I am trying to broadcast peer-to-peer through DataSnap REST
server Live webcamera.

We have already covered this topic on StackOverflow:

Delphi Firemonkey get/set TBitmap through RTTI
http://stackoverflow.com/questions/37511567/

And you already found a solution for it:

I found a way, there is a overload method for broadcast with TObject which
I didn't see it in the first place. So with that method I can broadcast any
type of TObject.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02