AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Wieder generische Functions results

Ein Thema von QuickAndDirty · begonnen am 14. Mai 2019 · letzter Beitrag vom 15. Mai 2019
 
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#12

AW: Wieder generische Functions results

  Alt 15. Mai 2019, 11:59
So kompilierts:

Edit: Oh du hast auch grad gepostet..
Ohne RTTI fällt mir auch keine Lösung ein...

Ist auch RTTI aber mit weniger overhead vielleicht?
Delphi-Quellcode:
uses
  TypInfo;

guid := PTypeInfo(TypeInfo(T))^.TypeData^.GUID;
Delphi-Quellcode:

uses
  System.RTTI;

class function TForm3.GetClient<T>(Addr: string): T;
var RIO: THTTPRIO;
    rtti: TRttiContext;
    intfType: TRttiInterfaceType;
begin
  Result := nil;
  RIO := nil;
  try
    rtti := TRttiContext.Create;
    try
      intfType := rtti.GetType(TypeInfo(T)) as TRttiInterfaceType;
      if Supports(RIO, intfType.GUID, Result) then
        RIO.URL := Addr
      else
        Result := nil;
    finally
      rtti.Free;
    end;
  finally
    if (Result = nil) then
      RIO.Free;
  end;
end;
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."

Geändert von Neutral General (15. Mai 2019 um 12:04 Uhr)
  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 02:44 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