David,<br><br>a basic test on a blank form shows that the following code doesn't work unless registerclass is called first (of course you'd only do this 1 time).<br><br>clearly they are not registering these classes by default for streaming. you will probably find that the Delphi IDE registers them all internally for DFM creation, but they haven't done it by default for end runtime code.<br>
<br>begin<br> RegisterClass(TButton);<br> with TComponentClass(FindClass('TButton')).Create(self) as tbutton do<br> begin<br> top := 10;<br> left := 10;<br> caption := 'hello';<br> width := 100;<br>
parent := self;<br> end;<br><br><div class="gmail_quote">On Mon, Jul 16, 2012 at 12:41 PM, David O'Brien <span dir="ltr"><<a href="mailto:Dave@iccs.co.nz" target="_blank">Dave@iccs.co.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Very frustrating, I'm getting "Class TButton not Found" with the below<br>
code. Everything in the uses clause is correct: I have a Tbutton on the<br>
form at design time. The form is in a .bpl if that will make a<br>
difference?<br>
<br>
// Simplified...<br>
Uses ..., StdCtrls, ...<br>
Var<br>
o: TComponent ;<br>
ot: String ;<br>
begin<br>
ot := 'TButton' ;<br>
o := TComponentClass(FindClass(ot)).Create(nil); <--- Class<br>
TButton Not Found<br>
end ;<br>
<div class="im HOEnZb"><br>
-----Original Message-----<br>
From: <a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a><br>
[mailto:<a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>] On Behalf Of Todd Martin<br>
Sent: Friday, 13 July 2012 4:27 p.m.<br>
</div><div class="im HOEnZb">To: NZ Borland Developers Group - Delphi List<br>
Subject: Re: [DUG] Creating an object at run time.<br>
<br>
</div><div class="HOEnZb"><div class="h5">b := TComponentClass(FindClass('TButton')).Create(nil);<br>
propinfo := GetPropInfo(b.classinfo,'left'); SetOrdProp(b,propinfo,100);<br>
<br>
> I want to create an object at runtime given a string with the object<br>
type. Is this possible or do I need to do a whole pile of if then<br>
else's? There is a limited number of different objects that need to be<br>
created. I then want to access the created objects properties by name<br>
and assign methods.<br>
><br>
> This is not for oleobjects, but VCL controls.<br>
><br>
> i.e.<br>
> b := CreateObject('TButton') ;<br>
> b.GetField('left') := 100 ;<br>
> ...<br>
><br>
> Help on any of these would be appreciated.<br>
><br>
> Cheers,<br>
> Dave.<br>
><br>
><br>
> _______________________________________________<br>
> NZ Borland Developers Group - Delphi mailing list<br>
> Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
> Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
> Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a><br>
> with Subject: unsubscribe<br>
<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with<br>
Subject: unsubscribe<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Kyley Harris<br>Harris Software<br>+64-21-671-821<br>