AGB  ·  Datenschutz  ·  Impressum  







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

Interfaces, Factory- und Singletonpattern

Ein Thema von Ghostwalker · begonnen am 5. Mai 2018 · letzter Beitrag vom 6. Mai 2018
Antwort Antwort
Schokohase
(Gast)

n/a Beiträge
 
#1

AW: Interfaces, Factory- und Singletonpattern

  Alt 5. Mai 2018, 07:38
Du suchst doch nach dem nächsten Konstruktor ohne Parameter, oder?

Wenn deine Klasse aber keine Konstruktor deklariert, dann wirst du in rt.GetDeclaredMethods keine Konstruktoren finden.

Wegen mir müsste man sich also durch die Vererbung wühlen und das sähe dann so aus:
Delphi-Quellcode:
function CreateInstance(AClass: TClass): TObject;
var
  ctx: TRttiContext;
  rt : TRttiInstanceType;
  rm : TRttiMethod;
begin
  ctx := TRttiContext.create;
  try
    rt := ctx.GetType(AClass.ClassInfo).AsInstance;

    while Assigned(rt) do
      begin
        for rm in rt.GetDeclaredMethods do
          begin
            if (rm.IsConstructor) and (Length(rm.GetParameters)=0)
            then
              begin
                result := rm.Invoke(AClass, [ ]).AsObject;
                Exit;
              end;
          end;

        rt := rt.BaseType;
      end;

    raise Exception.create('Fehlermeldung');

  finally
    ctx.Free;
  end;
end;
Und statt
Delphi-Quellcode:
  Supports(dm.Ainst,IVTDialogCall,intf);
  if (intf <> NIL) then
    result := intf.Call(value);
könntest du auch
Delphi-Quellcode:
  if Supports(dm.Ainst,IVTDialogCall,intf) then
    result := intf.Call(value);
schreiben (ist nur eine Kleinigkeit)
  Mit Zitat antworten Zitat
Antwort Antwort


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 23:25 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