AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Tvalue in unterschieldiche Typen von TRemotableXS wandeln
Thema durchsuchen
Ansicht
Themen-Optionen

Tvalue in unterschieldiche Typen von TRemotableXS wandeln

Ein Thema von fisipjm · begonnen am 10. Mai 2022 · letzter Beitrag vom 10. Mai 2022
 
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.079 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Tvalue in unterschieldiche Typen von TRemotableXS wandeln

  Alt 10. Mai 2022, 08:26
Delphi-Quellcode:
procedure {TForm.}GetObjectProperties(AObject: TObject; AList: TStrings);
var
  ctx: TRttiContext;
  rType: TRttiType;
  rProp, rProp2: TRttiProperty;
  rInstance: TRttiInstanceType;
  AValue: TValue;
  sVal: string;
const
  SKIP_PROP_TYPES = [tkUnknown, tkInterface];
begin
  if not Assigned(AObject) and not Assigned(AList) then
    Exit;

  ctx := TRttiContext.create;
  rType := ctx.GetType(AObject.ClassInfo);
  for rProp in rType.GetProperties do
  begin
    if (rProp.IsReadable) and not(rProp.PropertyType.TypeKind in SKIP_PROP_TYPES) then
    begin
      if rProp.PropertyType.TypeKind = tkClass then
      begin
        rInstance := rProp.PropertyType.AsInstance;
        AValue := rProp.GetValue(AObject);
        if AValue.IsInstanceOf(TRemotableXS) then
        begin
          sVal := TRemotableXS(AValue.AsObject).NativeToXS;
        end;
      end else
      begin
        AValue := rProp.GetValue(AObject);
        if AValue.IsEmpty then
        begin
          sVal := 'nil';
        end
        else
        begin
          if AValue.Kind in [tkUString, tkString, tkWString, tkChar, tkWChar] then
            sVal := QuotedStr(AValue.ToString)
          else
            sVal := AValue.ToString;
        end;
      end;

      AList.Add(rProp.Name + '=' + sVal);
    end;
  end;
end;

type
  TMyPropFullClass = class
  private
    FSomeString: TXSstring;
  public
    constructor Create;
    property SomeString: TXSstring read FSomeString;
  end;

constructor TMyPropFullClass.Create;
begin
  inherited;
  FSomeString := TXSstring.Create;
  FSomeString.XSToNative('Hello World');
end;

initialization
var MyData: TMyPropFullClass := TMyPropFullClass.Create;
var MyList: TStringList := TStringList.Create;
  GetObjectProperties(MyData, MyList);
  OutputDebugString(PChar(MyList.Text));
So funktioniert das für mich und den unteren kleinen Beispielcode.
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:52 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz