Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reflection

0 views
Skip to first unread message

bw

unread,
Feb 3, 2006, 10:09:45 AM2/3/06
to
Hi,

D2006 .NET WinForms

Is there any info on reflection and how to use FieldInfo.GetValue and
FieldInfo.SetValue???


I cant get past these 2 compile errors and have searched for days.......


var FormatStruct : System.Object;

//do other things to FormatStruct

ReturnValue := FieldInfo.GetValue(FormatStruct); >>>> COMPILE ERROR: Call to
abstract method FieldInfo.GetValue


ALSO

var FormatStruct : System.Object;

//do other things to FormatStruct

FieldInfo.SetValue(FormatStruct, NewValue); >>>> COMPILE ERROR: This form
of method call only allowed for class methods


regards,

Bernard


Craig Stuntz [TeamB]

unread,
Feb 3, 2006, 9:50:06 AM2/3/06
to
bw wrote:

> Is there any info on reflection and how to use FieldInfo.GetValue and
> FieldInfo.SetValue???

Yes, I recommend Jeffrey Richter's Applied Microsoft .NET Framework
Programming.

I think the problem you're having is that these methods should be used
as instance methods, not class methods. Also, FieldInfo works for the
value of fields, not types. So you want to do something like (untested,
but should be close to what you need):

var
BF: BindingFlags;
FI: FieldInfo;
begin
[...]
BF := // fill in appropriate flags for your app
FI := FormatStruct.GetType.GetField("FieldName", BF);
ReturnValue := FI.GetValue(FormatStruct);
end;

--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Please read and follow Borland's rules for the user of their
server: http://support.borland.com/entry.jspa?externalID=293

bw

unread,
Feb 3, 2006, 11:26:21 AM2/3/06
to
worked perfectly :)

i'm porting c# code and it used:

FieldInfo fieldInfo = structType.GetField( fieldName );
returnValue = fieldInfo.GetValue( formatStruct );

the two FieldInfo fieldInfo threw me, .... thanks very much :)

"Craig Stuntz [TeamB]" <craig_...@nospam.please [a.k.a. acm.org]> wrote
in message news:43e37bae$1...@newsgroups.borland.com...

0 new messages