Reputation: 1103
Is there a way to get Object data from its class procedure or function without instantiate it?
Upvotes: 0
Views: 674
Reputation: 1
Try to use something like that:
fClass := TComponentClass(GetClass(fNode.NodeName));
fControl := TControl(fClass.NewInstance);
fControl.Create(...)
Upvotes: 0
Reputation: 8573
You seem to have gotten it wrong:
Without instantiation, there is no data, and you cannot access data if it's not there.
Upvotes: 2
Reputation: 6364
To add to Ryan's answer, you can call the class functions without instantiating objects such as this:
var
MyInt: Integer begin
begin
MyInt := TMyClass.a;
Upvotes: 0
Reputation: 2562
I'm not sure this is what your talking about but...
type
tmyclasstype = class of tmyclass;
tmyclass = class(TObject)
class function a:integer;
class function b:tmyclass;
class function c:tmyclasstype;
end;
...
class tmyclass.function a:integer;
begin
result := 0;
end;
class tmyclass.function b:tmyclass;
begin
result := tmyclass.create;
end;
class tmyclass.function c:tmyclasstype;
begin
result := tmyclass;
end;
IIRC, these are all valid examples of class methods. Anything else is not valid as you can't access any structures, variables or non-classed methods of an object with out instantiating it.
Upvotes: 0