Like so:

procedure Test;
var
  SomeType: TClass;
  SomeObject: TObject;
begin
  SomeType := TStringList;
  SomeObject := SomeType.Create;
  (SomeObject as TStrings).Add('Hello World');
  ShowMessage((SomeObject as TStrings)[0]);
  SomeObject.Free;
end;

On Mon, Aug 23, 2010 at 7:05 PM, Frank Church <vfcli...@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 to
> let TBaseType be a variable so you can have some code like this.
>
> procedure (value:someType)
> var
>   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 at
> runtime. I remember doing something like that with Delphi of old, probably
> Delphi 3 or Delphi 7
>
> Can someone help me with this, with some use cases as well?
>
> Thanks
>
> --
> Frank Church
>
> =======================
> http://devblog.brahmancreations.com
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to