Bonjour à toutes et à tous,

je suis en D2009

Malgré que j'ai lu et relu cet article : http://reisubar.developpez.com/tutor...ngs-pchars/#LC

Je n'arrive toujours pas à passer une chaine String en Array de AnsiChar.

J'ai ce type :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
Type
  TFileLigneEcriture = Record
    TYP     : array[0..0]  of AnsiChar; // 1 (alphanumérique)
    JL      : array[0..1]  of AnsiChar; // 2
    DAT     : array[0..5]  of AnsiChar; // 6
    PIE     : array[0..4]  of AnsiChar; // 5
    LIB     : array[0..31] of AnsiChar; // 32
 
//...
end;
Je l'utilise de cette manière :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
procedure ExportFile(BaseLocal,Chemin_Destination,Nom_Destination: String; LecturePartielle: Boolean);
Var
  LigEcr  : TFileLigneEcriture;
  FStream : TStream;
  LChaine : Integer;
 
  Cnx        : TADOConnection;
  Qry        : TADOQuery;
  Tbl        : TADOTable;
 
  OldDate : TDate;
  OldPiece: String;
  ChaineTampon: String; // Pour essayer
begin
  FStream := TFileStream.Create(Chemin_Destination+Nom_Destination,fmCreate);
  Try
//...
        Tbl.Open;
        While Not eof do
        begin
// Bloc d'entête
          OldDate  := Tbl.FieldByName('Date').AsDateTime;
          OldPiece := Tbl.FieldByName('NumPiece').AsString;
          while (OldPiece = Tbl.FieldByName('NumPiece').AsString) And (Not eof) do
          begin
// Bloc Ligne
            LigEcr.TYP    := '2';
            LigEcr.JL     := '00'; // Non utilisé
ChaineTampon := FormatdateTime('ddmmyy',Tbl.FieldByName('Date').AsDateTime);
// ???            SetLength(ChaineTampon,Length(LigEcr.DAT));
            LigEcr.dAT    := PAnsiChar(ChaineTampon); // <== marche pas
            LigEcr.PIE    := LeftStr(Tbl.FieldByName('NumPiece').AsString,Length(LigEcr.PIE)); // <== marche pas
            LigEcr.LIB    := LeftStr(Tbl.FieldByName ('LibelleEcriture').AsAnsiString,Length(LigEcr.LIB)); // <== marche pas
 
// ...
end;

Je peux pas utilisé autre chose que des array[0..0] of AnsiChar sinon le fichier texte comportera des caractères étranges.

La je n'arrive pas à compiler, plus particulièrement transformer mon string en Array de char....

Merci pour votre aide.