[fpc-pascal] How to set a type as a variable?
leledumbo_cool at yahoo.co.id
Tue Aug 24 07:35:57 CEST 2010
Anthony Walter-3 wrote:
> Like so:
> procedure Test;
> SomeType: TClass;
> SomeObject: TObject;
> SomeType := TStringList;
> SomeObject := SomeType.Create;
> (SomeObject as TStrings).Add('Hello World');
> ShowMessage((SomeObject as TStrings));
> On Mon, Aug 23, 2010 at 7:05 PM, Frank Church <vfclists at gmail.com> wrote:
>> I did this kind of thing some time ago, but have forgotten the details.
>> Let us say you have something like TBaseType(Variable).Method, you want
>> let TBaseType be a variable so you can have some code like this.
>> procedure (value:someType)
>> variableType: TClass; //not quite sure here
>> variableType := TypeOf(value);
>> then further on you execute something like
>> variableType(Variable).Method, rather than TBaseType(Variable).Method
>> because you can't hard code TBaseType because can't tell what it will be
>> runtime. I remember doing something like that with Delphi of old,
>> Delphi 3 or Delphi 7
>> Can someone help me with this, with some use cases as well?
>> Frank Church
>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
View this message in context: http://old.nabble.com/How-to-set-a-type-as-a-variable--tp29517255p29518821.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal