Delphi/affichge tableau

Résolu
cs_Nadia16 Messages postés 6 Date d'inscription mercredi 6 mai 2009 Statut Membre Dernière intervention 16 mai 2009 - 7 mai 2009 à 16:26
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 7 mai 2009 à 22:25
Bon jour,
Je veut savoir comment on peut sauvegarder des vecteurs ou des tableaux (matrice)et les afficher en Delphi pour en suit les utiliser pour tracer des courbes par exemple.
Je suit débutante en programmation Delphi, j'utilise delphi 7.
Merci pour tout informations.

1 réponse

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
7 mai 2009 à 22:25
type
  TFoatPoint = packed record
    X, Y : single; { double; extended; }
  end;
  pFloatPoint = ^TFoatPoint;

  TVector = packed record
    A, B : TFloatPoint;
  end;
  pVector = ^TVector;

  TMatrix = array of TVector;
  pMatrix = ^TMatrix;

const
  FloatPointSize = SizeOf(TFloatPoint);
  VectorSize = SizeOf(TVector);
 

procedure LoadMatrix(const FileName: string; const ptr: pMatrix);
var L : integer;
begin
  with TFileStream.Create(FileName, fmOpenRead) do
  try
    read(L, SizeOf(integer));
    SetLength(ptr^, L);
    read(ptr^, L*VectorSize);
  finally
    Free;
  end;
end;

procedure SaveMatrix(const FileName: string; const ptr: pMatrix);
var L : integer;
begin
  L := length(ptr^);
  with TFileStream.Create(FileName, fmCreate) do
  try
    Write(L, SizeOf(Integer));
    Write(ptr^, L*VectorSize);
  finally
    Free;
  end;
end;

exemple :

// Declaration
var
  M : TMatrix;

// Definition du nombres de vecteur dans M (1)
SetLength(M, 1);

// Definition du vecteur 1 (index 0)

M[0].A.X := PI;

M[0].A.Y := PI;

M[0].B.X := PI*2;

M[0].B.Y := PI*2;




// Sauvegarder la matrice M
SaveMatrix('c:\matrix.mtx', @M);

// Vider la matrice M
Setlength(M, 0);

// Charger une matrice dans M

LoadMatrix('c:\matrix.mtx', @M);

// Verifier :
if Length(M) = 1 then
  ShowMessage('Youpi')
else
  ShowMessage('CACA BOUDIN PROUT!');
























<hr size="2" width="100%" />
3
Rejoignez-nous