How can I get the value of a record field

How can I get the value of a record field? eg,

Sorry, my description is not clear, I have such 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 nowmyRec fields are 1000, how can I get field dll values ​​up to 1000 form.edits, please use a write point, I want to use rtti records, but delphi2007 does not support this. if i use delphi2010, do you have other ways?

Blockquote

+3
source share
3 answers

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

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

Is this what you want?

+1
source

You can declare a record as follows

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;
+2
source

: " RTTI Delphi 2007?" , , Delphi 2010.

+2
source

Source: https://habr.com/ru/post/1793213/


All Articles