Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionunit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; type TPerformanceCounter = class public constructor Create; procedure Start; function Stop: Int64; private _nFrequency: Int64; _nBegin: Int64; end; var Form1: TForm1; implementation {$R *.dfm} constructor TPerformanceCounter.Create; begin inherited; QueryPerformanceFrequency(_nFrequency); end; procedure TPerformanceCounter.Start; begin QueryPerformanceCounter(_nBegin); end; function TPerformanceCounter.Stop: Int64; var nEnd: Int64; begin QueryPerformanceCounter(nEnd); Result:= ((nEnd - _nBegin) * 1000000) div _nFrequency; end; procedure TForm1.Button1Click(Sender: TObject); var counter: TPerformanceCounter; begin counter:= TPerformanceCounter.Create; counter.Start; Sleep(2); ShowMessage(IntToStr(counter.Stop) + ' microsecondes'); counter.Start; Sleep(10); ShowMessage(IntToStr(counter.Stop) + ' microsecondes'); FreeAndNil(counter); end; end.
var tabR : array of string; i:integer; begin setlength(tabR,Maxnbffich); for i:= 0 to high(tabR) do begin MaTable.Append; Matable.Chp1.Value := tabR[i]; -- -- MaTable.Post; end; end;
setlength(tabR,Maxnbffich); >> opérations de recherche de fichiers<<< for i:= 0 to high(tabR) do
Je ne suis pas parvenu à passer en paramètre un tableau dynamique (5*x) optionnel. Le compilateur me demandait une valeur par défaut et lorsque j'en donnais une il me disait qu'il n'en fallait pas (ou mauvais type ?).
procedure DisplayArray(lpArray: Array of String); overload; var nI: Integer; lpStr: String; begin lpStr:= ''; for nI:= 0 to High(lpArray) do lpStr:= lpStr + lpArray[nI]; ShowMessage(lpStr); end; procedure DisplayArray(); overload; begin DisplayArray([]); end; procedure TForm1.Button1Click(Sender: TObject); var lpArray: Array of String; begin SetLength(lpArray, 2); lpArray[0]:= 'toto'; lpArray[1]:= 'titi'; DisplayArray(lpArray); DisplayArray(); lpArray:= nil; end;
Il reste aussi le problème de la concaténation de tableaux multi-colonnes.
procedure TForm1.Button1Click(Sender: TObject); var lpArray1: Array of Array of String; lpArray2: Array of Array of String; nArray1Len: Integer; lpResult: String; nI: Integer; begin SetLength(lpArray1, 2); SetLength(lpArray1[0], 2); SetLength(lpArray1[1], 2); lpArray1[0, 0]:= '1'; lpArray1[0, 1]:= 'a'; lpArray1[1, 0]:= '2'; lpArray1[1, 1]:= 'b'; SetLength(lpArray2, 2); SetLength(lpArray2[0], 2); SetLength(lpArray2[1], 2); lpArray2[0, 0]:= '3'; lpArray2[0, 1]:= 'c'; lpArray2[1, 0]:= '4'; lpArray2[1, 1]:= 'd'; // Concaténation nArray1Len:= Length(lpArray1); SetLength(lpArray1, nArray1Len + Length(lpArray2)); for nI:= 0 to High(lpArray2) do begin SetLength(lpArray1[nArray1Len + nI], 2); lpArray1[nArray1Len + nI][0]:= lpArray2[nI][0]; lpArray1[nArray1Len + nI][1]:= lpArray2[nI][1]; end; // Affichage for nI:= 0 to High(lpArray1) do begin lpResult:= lpResult + lpArray1[nI][0]; lpResult:lpResult + ' '; lpResult:= lpResult + lpArray1[nI][1]; lpResult:= lpResult + sLineBreak; end; ShowMessage(lpResult); // Libération for nI:= 0 to High(lpArray1) do begin lpArray1[nI]:= nil; end; lpArray1:= nil; for nI:= 0 to High(lpArray2) do begin lpArray2[nI]:= nil; end; lpArray2:= nil; end;