IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Un code qui marche sous Delphi 7 et ne marche pas sous Berlin


Sujet :

Delphi

  1. #1
    Membre actif

    Inscrit en
    Mai 2010
    Messages
    401
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 401
    Points : 294
    Points
    294
    Par défaut Un code qui marche sous Delphi 7 et ne marche pas sous Berlin
    Bonsoir ,
    Ce petit code marche bien sous Delphi 7 mais non plus sous Berlin



    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;
     
    type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        Edit1: TEdit;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
    function GetIdeSerialNumber0 ():string;
    const IDENTIFY_BUFFER_SIZE = 512;
    type
     TIDERegs = packed record
       bFeaturesReg     : BYTE; // Used for specifying SMART "commands".
       bSectorCountReg  : BYTE; // IDE sector count register
       bSectorNumberReg : BYTE; // IDE sector number register
       bCylLowReg       : BYTE; // IDE low order cylinder value
       bCylHighReg      : BYTE; // IDE high order cylinder value
       bDriveHeadReg    : BYTE; // IDE drive/head register
       bCommandReg      : BYTE; // Actual IDE command.
       bReserved        : BYTE; // reserved for future use.  Must be zero.
     end;
     TSendCmdInParams = packed record
       cBufferSize  : DWORD;
       irDriveRegs  : TIDERegs;
       bDriveNumber : BYTE;
       bReserved    : Array[0..2] of Byte;
       dwReserved   : Array[0..3] of DWORD; 
       bBuffer      : Array[0..0] of Byte;  // Input buffer.
     end; 
     TIdSector = packed record
       wGenConfig                 : Word; 
       wNumCyls                   : Word;
       wReserved                  : Word; 
       wNumHeads                  : Word;
       wBytesPerTrack             : Word; 
       wBytesPerSector            : Word;
       wSectorsPerTrack           : Word;
       wVendorUnique              : Array[0..2] of Word;
       sSerialNumber              : Array[0..19] of CHAR; 
       wBufferType                : Word;
       wBufferSize                : Word; 
       wECCSize                   : Word;
       sFirmwareRev               : Array[0..7] of Char;
       sModelNumber               : Array[0..39] of Char;
       wMoreVendorUnique          : Word;
       wDoubleWordIO              : Word;
       wCapabilities              : Word;
       wReserved1                 : Word;
       wPIOTiming                 : Word;
       wDMATiming                 : Word;
       wBS                        : Word; 
       wNumCurrentCyls            : Word;
       wNumCurrentHeads           : Word; 
       wNumCurrentSectorsPerTrack : Word;
       ulCurrentSectorCapacity    : DWORD;
       wMultSectorStuff           : Word;
       ulTotalAddressableSectors  : DWORD; 
       wSingleWordDMA             : Word;
       wMultiWordDMA              : Word; 
       bReserved                  : Array[0..127] of BYTE;
     end;
     PIdSector = ^TIdSector;
     TDriverStatus = packed record
       bDriverError : Byte;
       bIDEStatus   : Byte;
       bReserved    : Array[0..1] of Byte;
       dwReserved   : Array[0..1] of DWORD;
     end;
     TSendCmdOutParams = packed record
       cBufferSize  : DWORD;
       DriverStatus : TDriverStatus;
       bBuffer      : Array[0..0] of BYTE;
     end;
     var
       hDevice : THandle;
       cbBytesReturned : DWORD;
    //    ptr : PChar;
       SCIP : TSendCmdInParams;
       aIdOutCmd : Array [0..(SizeOf(TSendCmdOutParams)+IDENTIFY_BUFFER_SIZE-1)-1] of Byte;
       IdOutCmd  : TSendCmdOutParams absolute aIdOutCmd;
     
    procedure ChangeByteOrder(var Data; Size : Integer );
    var
     ptr : PChar;
     i : Integer;
     c : Char;
    begin
       ptr := @Data;
       for i := 0 to (Size shr 1)-1 do
       begin
         c := ptr^;
         ptr^ := (ptr+1)^;
         (ptr+1)^ := c;
         Inc(ptr,2);
       end;
     end;
    begin
     Result := ''; // return empty string on error
     if SysUtils.Win32Platform=VER_PLATFORM_WIN32_NT then // Windows NT, Windows 2000
     
    begin
    //???? EU?? PhysicalDrive0 C?? PhysicalDrive1 C? PhysicalDrive2
      hDevice := CreateFile( '\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
     FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0 );
     end
     else // Version Windows 95 OSR2, Windows 98
     hDevice := CreateFile( '\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 );
     if hDevice=INVALID_HANDLE_VALUE then Exit;
     try
       FillChar(SCIP,SizeOf(TSendCmdInParams)-1,#0);
       FillChar(aIdOutCmd,SizeOf(aIdOutCmd),#0);
       cbBytesReturned := 0;
       with SCIP do
       begin
       cBufferSize  := IDENTIFY_BUFFER_SIZE;
       bDriveNumber := 0;
      with irDriveRegs do
      begin
        bSectorCountReg  := 1;
        bSectorNumberReg := 1;
        bDriveHeadReg    := $A0;
        bCommandReg      := $EC;
       end;
       end;
       if not DeviceIoControl( hDevice, $0007c088, @SCIP, SizeOf(TSendCmdInParams)-1,
         @aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil ) then Exit;
     finally
       CloseHandle(hDevice);
     end;
     with PIdSector(@IdOutCmd.bBuffer)^ do
     begin
       ChangeByteOrder( sSerialNumber, SizeOf(sSerialNumber) );
       (PChar(@sSerialNumber)+SizeOf(sSerialNumber))^ := #0;
       Result := PChar(@sSerialNumber);
     end;
    end;
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
       Edit1.Text := GetIdeSerialNumber0  ;
    end;
     
    end.
    Avez vous une idée SVP ...

  2. #2
    Membre expérimenté
    Avatar de retwas
    Homme Profil pro
    Développeur Java/Delphi
    Inscrit en
    Mars 2010
    Messages
    698
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Java/Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 698
    Points : 1 608
    Points
    1 608
    Billets dans le blog
    4
    Par défaut
    Cela ne fait rien ou tu as une erreur quelque part ? Il y a le passage à Unicode depuis D7.

  3. #3
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Bonjour,
    Char depuis le passage à l'unicode est en fait un WideChar
    PChar un PWideChar
    il faut donc les redéclarer Char->AnsiChar PChar -> PAnsiChar

    je ne me suis arrêté qu'a ces deux là , mais comme il y a pas mal d'opérations par pointeur
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  4. #4
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Bonjour,

    Quelques liens qui devraient vous aider pour la migration Unicode :

    https://www.embarcadero.com/rad-in-a...upgrade-center

    https://www.embarcadero.com/images/d...-migration.pdf

  5. #5
    Membre actif

    Inscrit en
    Mai 2010
    Messages
    401
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 401
    Points : 294
    Points
    294
    Par défaut
    Citation Envoyé par SergioMaster Voir le message
    Bonjour,
    Char depuis le passage à l'unicode est en fait un WideChar
    PChar un PWideChar
    il faut donc les redéclarer Char->AnsiChar PChar -> PAnsiChar
    Merci beaucoup Sergio , c'est super ça marche très très bien.

    Thierry Laborde et retwas Merci beaucoup pour le suivi et pour les liens .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] Code VBA qui fonctionne sous XL 2007 mais ne fonctionne pas sous ACCESS 2003.
    Par casdidier dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 12/09/2014, 00h43
  2. OnKeyDown ne répond pas sous Delphi
    Par Stevens.Georges dans le forum Langage
    Réponses: 2
    Dernier message: 21/03/2008, 11h14
  3. Réponses: 3
    Dernier message: 06/03/2006, 09h59
  4. Installer un composant .pas sous Delphi 2005 ???
    Par rpoulin dans le forum EDI
    Réponses: 3
    Dernier message: 01/11/2005, 13h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo