1

RTTI を介して TBitmap を取得/設定するにはどうすればよいですか? 私は次のようにしました:

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;

(TBitmapOfItem @ 07A06280) 文字列を TBitmap に変換するには、次のようにします。

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;

これは私のクラスです

  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;

ブロードキャスト メッセージとして別のクライアントに渡すために、TBitmap を文字列に変換する必要があります。

4

0 に答える 0