was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

34 Visitors Online


 
...die von einer Form Klasse registrierten Klassen herausfinden?
Autor: P. Below
Homepage: http://www.teamb.com
[ Tip ausdrucken ]  

Tip Bewertung (6):  
     




{
  Question: How can I get all classes that are currently registered in my Application?

  Answer: There is no way to get at classes registered via RegisterClasses, since the
  list holding these is private to the classes unit.You can get at the classes
  registered on a Form, however, since those use a Table connected to the Form
  classes class record.The following is based on some spelunking in the classes unit:
}

// defined in classes.pas
type
  
PFieldClassTable = ^TFieldClassTable;
  TFieldClassTable = packed record
    
Count: Smallint;
    Classes: array[0..8191] of ^TPersistentClass;
  end;


function GetFieldClassTable(AClass: TClass): PFieldClassTable; assembler;
asm
    
MOV EAX,[EAX].vmtFieldTable
    OR EAX,EAX
    JE @@1
    MOV EAX,[EAX+2].Integer
    @@1:
end;
  // end of quote from classes.pas

procedure TForm1.Button1Click(Sender: TObject);

  procedure Display(const S: string);
  begin
    
memo1.Lines.Add(S);
  end;
  
var
  
pFCT: PFieldClassTable;
  aClass: TClass;
  i: SmallInt;
begin
  
memo1.Clear;
  aClass := Classtype;
  while aClass <> TPersistent do
  begin
    
Display('Registered classes for class ' + aClass.ClassName);
    pFCT := GetFieldClasstable(aClass);
    if not Assigned(pFCT) then
      
Display(' No classes registered')
    else
    begin
      
Display(Format(' %d classes registered', [pFCT^.Count]));
      for i := 0 to pFCT^.Count - 1 do
        
Display(' ' + pFCT^.Classes[i]^.ClassName);
    end;
    aClass := aClass.ClassParent;
  end
end
;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners