Einzelnen Beitrag anzeigen

brechi

Registriert seit: 30. Jan 2004
823 Beiträge
 
#1

Record Größe zur Laufzeit bestimmen

  Alt 18. Apr 2008, 19:21
bisher habe ich folgenden code um die größe von Records (Alignment 1,2,4,8) zur Laufzeit zu bestimmen
der Code sollte selbsterklärend sein, aber ich bin zu dumm dafür oder einfach zu müde, also wenn sich jemand dran machen will dann gerne
Delphi-Quellcode:
function GetRecordSize(types: array of TxType; Alignment: Integer): Integer;
var
  i: integer;
  max: integer;
begin
  max := 0;
  for i := low(types) to high(types) do
  case types[i] of
    xInteger: if max < 4 then max := 4;
    xByte: if max < 1 then max := 1;
    xDouble: if max < 8 then max := 8;
    xExtended: if max < 10 then max := 10;
    xWord: if max < 2 then max := 2;
  end;
  if max < Alignment then
    Alignment := max;

  result := 0;
  for i := low(types) to high (types) do
  case types[i] of
    xInteger: if result mod 4 = 0 then inc(result,4) else inc (result,4 + alignment-(result mod alignment+1));
    xByte: if result mod 1 = 0 then inc(result,1) else inc (result,1 + alignment-(result mod alignment+1));
    xDouble: if result mod 8 = 0 then inc(result,8) else inc (result,8 + alignment-(result mod alignment+1));
    xExtended: if result mod 10 = 0 then inc(result,10) else inc (result,10 + alignment-(result mod alignment+1));
    xWord: if result mod 2 = 0 then inc(result,2) else inc (result,2 + alignment-(result mod alignment+1));
  end;
  if result mod alignment <> 0 then
    result := result + alignment-(result mod alignment);
end;

type b = record
  b: byte;
  a: extended;
  i: integer;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  form1.caption := inttostr(GetRecordSize([xByte, xExtended, xInteger],8))+' '+inttostr(SizeOf(b))
der obice dode ist im mom schwachsinn hab den mittlerweile wieder geändert :/ vill bekommts jemand hin
  Mit Zitat antworten Zitat