开发者

how can i get the record field value

开发者 https://www.devze.com 2023-02-12 05:17 出处:网络
how can i get the record field value?for example, sorry , my Description is not clear, i have a big recordlike this

how can i get the record field value? for example,

sorry , my Description is not clear, i have a big record like this

type
myRec=record
a:byte;
c:single;
////  a lot of  fields
end;
var
nowmyrec:myrec;
tmystr:TMemoryStream;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
tmystr:tmemerystream.create;
tmystr.LoadFromFile(ExtractFilePath(Application.exename)+'1.data');
tmstr.Position:=0;
tmstr开发者_开发问答.readbuffer(nowmyRec,sizeof(myRec));
end;

if fields of nowmyRec is 1000, how can i get the dll of field value to 1000 form.edits , please donot use record point ,i want use rtti of record,but delphi2007 donot support that. if i donot use delphi2010 ,do you have other ways?

Blockquote


You question is "how do I use RTTI to access record fields in Delphi 2007?" The answer is that you can't, you need Delphi 2010.


You can declare the record like this

type
    TmyRec = record
        a: byte;
        b: array [0 .. 35] of widechar;
        c: single;
    end;

And use it like this

var
    myRec1, MyRec2: TmyRec;
    ms: TMemoryStream;
    x: single;
begin
    ms := TMemoryStream.Create;
    try
        // Create a record
        myRec1.a :=1;
        myRec1.c :=1.50;

        // Save record to TMemoryStream
        ms.WriteBuffer(myRec1, SizeOf(TmyRec));

        // Read one record from TMemoryStream
        ms.Position := 0;
        ms.ReadBuffer(myRec2, SizeOf(TMyRec));

        // Get a value
        x := MyRec2.c;
        ShowMessage(FloatToStr(x));
    finally
        ms.Free;
    end;
end;


you need to first declare the record variable like Rec1: myRec;

var
  Rec1: myRec;
  myValue: Single;
begin
  myValue := Rec1.c
end;

Is this what you want?

0

精彩评论

暂无评论...
验证码 换一张
取 消