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

EDI Delphi Discussion :

Unsafe typecast of 'TDBGrid' to 'TDrawGrid'


Sujet :

EDI Delphi

  1. #1
    Membre habitué Avatar de sondo
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2004
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Service public

    Informations forums :
    Inscription : Août 2004
    Messages : 540
    Points : 162
    Points
    162
    Par défaut Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    Bonjour,

    Je rencontre des problème après le passage de Delphi5 je suis passé à Delphi7.
    Quand je compile mon programme écrit en Delphi5 dans l'EDI de Delphi7 j'ai cet erreur : Unsafe typecast of 'TDBGrid' to 'TDrawGrid', alors que mon programme s'exécutait bien dand Delphi5.
    Voici le code incriminé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ColS := format('%2d',[TdrawGrid(DbGrid1).col]);
    Pouvez-vous m'aider à comprendre?

    Merci d'avance.

  2. #2
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 445
    Points
    28 445
    Par défaut
    ben c'est normal, TDBGrid n'est pas une TDrawGrid
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  3. #3
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 459
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 459
    Points : 24 873
    Points
    24 873
    Par défaut
    Tu as 3 warnings du .NET a retiré en D7 Win32, normalement, cela ne devrait pas être une erreur

    utilise plutôt un TDBGridHack pour l'astuce du hack de propriété
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    type
      TDBGridHack = class(TDBGrid)
      public
        property Col;
      end;
    C'est vrai que TdrawGrid augmente la visibilité de Col, c'est une astuce souvent utilisée mais périlleuse

    Tu passe de Delphi 5 à 7, pense que le 17 (XE3) est sorti !
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  4. #4
    Membre habitué Avatar de sondo
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2004
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Service public

    Informations forums :
    Inscription : Août 2004
    Messages : 540
    Points : 162
    Points
    162
    Par défaut
    Salut Paul TOTH,

    Merci pour ton aide. Mais je ne comprend pas du tout! En Delphi5 cela marchait très bien. Pourquoi en Delphi7 cela pose problème?
    Du coup mon application ne fonctionne plus. En plus je ne sais pas qu'est-ce qu'il faut mettre à la place pour satisfaire Delphi7. Voici tous les codes qui posent problème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dm_num := DbGrid1.Columns.Grid.Fields[TdrawGrid(DbGrid1).Col-1].AsString;
    Erreur : Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ShellExecute(Handle,'open',PChar('c:\Frais_medicaux_agent.htm'),nil,nil,SW_SHOW);
    Erreur : [Warning] Menu_Gle.pas(434): Unsafe type 'PChar'
    Erreur : [Warning] Menu_Gle.pas(476): Unsafe type 'Pointer'
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    GetMem(VerInfo, VerInfoSize);
    Erreur : [Warning] Menu_Gle.pas(485): Unsafe code 'GetMem'
    [Warning] Menu_Gle.pas(485): Unsafe type 'VerInfo: Pointer'
    [code]GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);/CODE]
    Erreur : [Warning] Menu_Gle.pas(487): Unsafe type 'PChar'
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if GetTimeZoneInformation(TimeZoneInfo) <> $FFFFFFFF then 
            Bias := TimeZoneInfo.Bias / 1440; // 60x24 
          GetFileTime(h, @Info1, @Info2, @Info3);
    Erreur : [Warning] Mise_jour.pas(44): Unsafe code '@ operator'

    Voici un récapitulatif des erreurs :
    Build
    [Warning] Liste_dm_four.pas(58): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(66): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(67): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(130): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(131): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(214): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_dm_four.pas(215): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_frs_piece_en_cours.pas(46): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_frs_piece_en_cours.pas(54): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_frs_piece_en_cours.pas(55): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_frs_piece_en_cours.pas(68): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_frs_piece_en_cours.pas(69): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(56): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(64): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(65): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(79): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(80): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(92): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(93): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(104): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Liste_fournisseurs.pas(105): Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
    [Warning] Situation_frais_agent.pas(137): Unsafe type 'PChar'
    [Warning] Situation_frais_agent.pas(173): Unsafe type 'PChar'
    [Warning] Situation_frais_agent.pas(209): Unsafe type 'PChar'
    [Warning] Situation_frais_agent.pas(244): Unsafe type 'PChar'
    [Warning] Boite_A_Propos.pas(32): Unsafe type 'Pointer'
    [Warning] Boite_A_Propos.pas(35): Unsafe type 'PChar'
    [Warning] Boite_A_Propos.pas(41): Unsafe code 'GetMem'
    [Warning] Boite_A_Propos.pas(41): Unsafe type 'VerInfo: Pointer'
    [Warning] Boite_A_Propos.pas(43): Unsafe type 'PChar'
    [Warning] Boite_A_Propos.pas(43): Unsafe type 'VerInfo: Pointer'
    [Warning] Boite_A_Propos.pas(44): Unsafe type 'VerInfo: Pointer'
    [Warning] Boite_A_Propos.pas(44): Unsafe type 'Pointer'
    [Warning] Boite_A_Propos.pas(55): Unsafe code 'FreeMem'
    [Warning] Boite_A_Propos.pas(55): Unsafe type 'VerInfo: Pointer'
    [Warning] Menu_Gle.pas(434): Unsafe type 'PChar'
    [Warning] Menu_Gle.pas(476): Unsafe type 'Pointer'
    [Warning] Menu_Gle.pas(479): Unsafe type 'PChar'
    [Warning] Menu_Gle.pas(485): Unsafe code 'GetMem'
    [Warning] Menu_Gle.pas(485): Unsafe type 'VerInfo: Pointer'
    [Warning] Menu_Gle.pas(487): Unsafe type 'PChar'
    [Warning] Menu_Gle.pas(487): Unsafe type 'VerInfo: Pointer'
    [Warning] Menu_Gle.pas(488): Unsafe type 'VerInfo: Pointer'
    [Warning] Menu_Gle.pas(488): Unsafe type 'Pointer'
    [Warning] Menu_Gle.pas(499): Unsafe code 'FreeMem'
    [Warning] Menu_Gle.pas(499): Unsafe type 'VerInfo: Pointer'
    [Warning] SplashScreen.pas(32): Unsafe type 'Pointer'
    [Warning] SplashScreen.pas(35): Unsafe type 'PChar'
    [Warning] SplashScreen.pas(41): Unsafe code 'GetMem'
    [Warning] SplashScreen.pas(41): Unsafe type 'VerInfo: Pointer'
    [Warning] SplashScreen.pas(43): Unsafe type 'PChar'
    [Warning] SplashScreen.pas(43): Unsafe type 'VerInfo: Pointer'
    [Warning] SplashScreen.pas(44): Unsafe type 'VerInfo: Pointer'
    [Warning] SplashScreen.pas(44): Unsafe type 'Pointer'
    [Warning] SplashScreen.pas(55): Unsafe code 'FreeMem'
    [Warning] SplashScreen.pas(55): Unsafe type 'VerInfo: Pointer'
    [Warning] Mise_jour.pas(44): Unsafe code '@ operator'
    [Warning] Mise_jour.pas(44): Unsafe code '@ operator'
    [Warning] Mise_jour.pas(44): Unsafe code '@ operator'

  5. #5
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 445
    Points
    28 445
    Par défaut
    alors ce ne sont pas des erreurs mais des warning, D7 en a introduit un paquet en prévision du passage à .Net, il alerte dès qu'un usage de pointeur est fait.

    si tu penses que ton code ne justifie ce warning tu peux les désactiver (F1 sur le message)
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  6. #6
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Citation Envoyé par sondo Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dm_num := DbGrid1.Columns.Grid.Fields[TdrawGrid(DbGrid1).Col-1].AsString;
    Voici un récapitulatif des erreurs :
    Ca tu pourrais le transformer en utilisant le dataset ...

    Genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    DM_NUM := LeComposantBaseDeDonnee.FieldByName('LE Nom Du champ').AsString;
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

Discussions similaires

  1. TDBGRID - Couleur de fond d'une seule cellule
    Par cgo dans le forum Bases de données
    Réponses: 5
    Dernier message: 11/09/2009, 10h16
  2. TDBGrid et images
    Par X Trips dans le forum Bases de données
    Réponses: 2
    Dernier message: 17/12/2003, 11h38
  3. Table Access et Accents dans TDBGrid
    Par puzpuz_vannes dans le forum Bases de données
    Réponses: 3
    Dernier message: 13/11/2003, 22h23
  4. [TDBGrid] Multisélection de lignes pour suppression
    Par littledoudou dans le forum C++Builder
    Réponses: 9
    Dernier message: 05/11/2003, 10h42
  5. Dimensions des colonnes d'un TDBGrid
    Par osmose22 dans le forum C++Builder
    Réponses: 4
    Dernier message: 11/12/2002, 11h27

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