Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.883 Beiträge
 
Delphi 12 Athens
 
#11

AW: Wieder generische Functions results

  Alt 15. Mai 2019, 11:52
OK ich habs!
Kann man das irgendwie ohne RTTI hinbekommen?

Delphi-Quellcode:
Class Function TWSClient.GetClient<T>(Addr: string):T;
var RIO: THTTPRIO;
    aGuid:TGuid;
begin
  Result := nil;
  RIO := GetLocalRio;
  try
    //Result := (RIO as T);//[dcc32 Fehler] E2015 Operator ist auf diesen Operandentyp nicht anwendbar

    //Result := T(RIO);//Das geht Aber es produziert zugriffsverletzungen... dank Refcount;

    aGuid := TRttiInterfaceType(TRttiContext.Create.GetType(TypeInfo(T))).GUID ;

    if not Supports(RIO,aGuid,Result) then
      Result := nil;

    RIO.URL := Addr

  finally
    if (Result = nil) then
      RIO.Free;
  end;
End;
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat