🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.delphi
Article #346482

Re: Czy można się odwołać do zmiennej po nazwie tekstem?

#346482
From: Jan Drawski
Date: Wed, 21 Mar 2018 11:59
26 lines
1886 bytes
> procedure ChangeVal(Obj: TObject; ValName: String; Val: TValue);
> var
>    ctx: TRttiContext;
>    rttitype: TRttiType;
>    rttiprop: TRttiProperty;
>    value: TValue;
> begin
>    rttitype := ctx.GetType(Obj.ClassType);
>    rttiprop := rttitype.GetProperty(ValName);
>    rttiprop.SetValue(Obj, Val.ToString);
> end;

".ToString" nie jest potrzebne i na końcu dodałbym jeszcze ctx.Free;
Procedura może wyglądać tak:

procedure ChangeVal(Obj: TObject; ValName: String; Val: TValue);
var
   ctx: TRttiContext;
begin
   ctx.GetType(Obj.ClassType).GetProperty(ValName).SetValue(Obj, Val);
   ctx.Free;
end;

-- 
Pozdrawiam
Janek
Technical Details
Message-ID: <5ab2493c$0$1007$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!peer02.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
References: <121d9004-81f5-4ce9-9c86-3e2c46815153@googlegroups.com> <1hiujpxl68d3y.dlg@tyczka.com> <c6e3f56f-5dc4-40d6-87b6-58e205049909@googlegroups.com> <5ab23db8$0$669$65785112@news.neostrada.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!peer02.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Czy można się odwołać do
 zmiennej po nazwie tekstem?
Newsgroups: pl.comp.lang.delphi
References: <121d9004-81f5-4ce9-9c86-3e2c46815153@googlegroups.com> <1hiujpxl68d3y.dlg@tyczka.com> <c6e3f56f-5dc4-40d6-87b6-58e205049909@googlegroups.com> <5ab23db8$0$669$65785112@news.neostrada.pl>
From: Jan Drawski <dfghdfg@o2.pl>
Date: Wed, 21 Mar 2018 12:59:56 +0100
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
MIME-Version: 1.0
In-Reply-To: <5ab23db8$0$669$65785112@news.neostrada.pl>
Lines: 26
Message-ID: <5ab2493c$0$1007$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 37.47.35.253
X-Trace: 1521633596 unt-rea-a-02.news.neostrada.pl 1007 37.47.35.253:23419
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1762
X-Received-Body-CRC: 3795909488
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit