Autor Beitrag
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Di 16.03.04 08:32 
::specialwork

Recht hast du - aber nur bedingt, weil ich dir ja schon geschrieben habe, wie du per IDispatch an die TypeInfo kommst. Weiters hast du ja schon geschrieben, deine Objekte implementieren IDispatch (was ja auch bei fast allen der Fall ist). Worauf wartest du also noch ? Hophop, hinsetzen und implementieren ! :)

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.
specialwork Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

Windows XP Professional; Windows Server 2003
Delphi 7 Prof, Delphi 8.Net
BeitragVerfasst: Fr 19.03.04 00:41 
Titel: TClassCollector
Hallo,

Ich hab mal eine Komponente erzeugt. Ihr könnt mir ja mal eure Mainung und Verbesserungsvorschläge dazu sagen. Die Komponente ist natürlich erst in der Beta-Phase.

Gruß, Tom

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
unit UClassCollector;

interface

uses
  SysUtils, Classes, Windows, ComObj, ActiveX, Dialogs;

type
  TClassCollector = class;
  TMethodes = class;
  TMethode = class;

  TMethode = class(TCollectionItem)
  private
    fDisplayName: string;
    fMethodeName: string;
    fMethodeMemberID: Int64;
  public
    constructor Create(Collection: TCollection); override;
    destructor Destroy; override;
  protected
    function GetOwner: TPersistent; override;
    function GetDisplayName: stringoverride;
  published
    property DisplayName: string read fDisplayName;
    property MethodeName: string read fMethodeName;
    property MethodeMemberID: Int64 read fMethodeMemberID default -1;
  end;

  TMethodes = class(TCollection)
  private
    fOwner: TClassCollector;
    function GetItem(Index: Integer): TMethode;
  public
    constructor Create(AOwner: TPersistent; ItemClass: TMethode);
    property Methodes[Index: Integer]: TMethode read GetItem; default;
    function Add: TMethode;
  protected
    procedure Update(Item: TCollectionItem); override;
  end;

  TClassCollector = class(TComponent)
  private
    fCOMClassName: string;
    fMethodes: TMethodes;
    fErrorString: string;
    function GetMethodes: TMethodes;
    procedure SetMethodes(Value: TMethodes);
    procedure SetCOMClassName(Value: string);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Refresh;
  published
    property Methodes: TMethodes read GetMethodes write SetMethodes;
    property COMClassName: string read fCOMClassName write SetCOMClassName;
    property ErrorString: string read fErrorString;
  end;

procedure Register;

implementation

uses Variants;

procedure Register;
begin
  RegisterComponents('Specialwork COM', [TClassCollector]);
end;

// TMethode

constructor TMethode.Create(Collection: TCollection);
begin
  inherited Create(Collection);
end;

destructor TMethode.Destroy;
begin
  inherited Destroy;
end;

function TMethode.GetOwner: TPersistent;
begin
  Result := Collection.Owner;
end;

function TMethode.GetDisplayName: string;
begin
  Result := fDisplayName;
  if Result = '' then
    Result := inherited GetDisplayName;
end;

// TMethodes

function TMethodes.GetItem(Index: Integer): TMethode;
begin
  Result := inherited Items[Index] as TMethode;
end;

constructor TMethodes.Create(AOwner: TPersistent; ItemClass: TMethode);
begin
  fOwner := TClassCollector(AOwner);
  inherited Create(TMethode);
end;

function TMethodes.Add: TMethode;
begin
  Result := inherited Add as TMethode;
end;

procedure TMethodes.Update(Item: TCollectionItem);
begin
  inherited Update(Item);
end;

// TClassCollector

constructor TClassCollector.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  fMethodes := TMethodes.Create(AOwner, nil);
end;

destructor TClassCollector.Destroy;
begin
  fMethodes.Destroy;
  inherited Destroy;
end;

procedure TClassCollector.SetCOMClassName(Value: string);
begin
  fCOMClassName := Value;
  Refresh;
end;

function TClassCollector.GetMethodes: TMethodes;
begin
  Result := fMethodes;
end;

procedure TClassCollector.Refresh;
var
  Dispatch: IDispatch;
  NewMethode: TMethode;
  HasMethodes: Boolean;
  IHasMethodes: Integer;
  TypeInfo: ITypeInfo;
  TypeAttr: PTypeAttr;
  MethodeDescription: PFuncDesc;
  MethodeDescriptionList: TBSTRList;
  MethodeCount: Integer;
  MethodeNames: integer;
  Temp: Variant;
  x: Integer;
begin
  fMethodes.BeginUpdate;
  fMethodes.Clear;

  fErrorString := '';

  MethodeDescription := new(PFuncDesc);

  try
    try
      Dispatch := CreateOleObject(COMClassName);
      Dispatch.GetTypeInfoCount(IHasMethodes);
      HasMethodes := IHasMethodes > 0;

      if HasMethodes then begin
        Dispatch.GetTypeInfo(0, GetUserDefaultLCID, TypeInfo);
        TypeInfo.GetTypeAttr(TypeAttr);

        for MethodeCount := 0 to TypeAttr.cFuncs - 1 do begin
          TypeInfo.GetFuncDesc(MethodeCount, MethodeDescription);
          TypeInfo.GetNames(MethodeDescription.memid, @MethodeDescriptionList,
            1, MethodeNames);

          NewMethode := fMethodes.Add;
          NewMethode.fMethodeMemberID := MethodeDescription.memid;
          NewMethode.fMethodeName := MethodeDescriptionList[0];
          NewMethode.fDisplayName := MethodeDescriptionList[0];
        end;
      end;
    except
      on e: Exception do begin
        fErrorString := e.Message;
      end;
    end;
  finally
    try
      try
        for x:=0 to fMethodes.Count-1 do begin
          if uppercase(fMethodes[x].fMethodeName) = 'QUIT' then begin
            Temp := Dispatch;
            Temp.Quit;
          end;
        end;
      except
        on e: Exception do begin
          OutputDebugString(PChar(e.Message));
        end;
      end;
    finally
      Dispatch := Unassigned;
    end;
  end;

  fMethodes.EndUpdate;
end;

procedure TClassCollector.SetMethodes(Value: TMethodes);
begin
  GetMethodes.Assign(Value);
end;

end.
specialwork Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

Windows XP Professional; Windows Server 2003
Delphi 7 Prof, Delphi 8.Net
BeitragVerfasst: Di 23.03.04 18:38 
Wie :!: Kein Kommentar :?: