Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > Delphi > EDI
EDI Configuration/utilisation de l'EDI
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 04/10/2012, 10h34   #1
sondo
Membre régulier
 
Avatar de sondo
 
Inscription : août 2004
Messages : 443
Détails du profil
Informations forums :
Inscription : août 2004
Messages : 443
Points : 84
Points : 84
Envoyer un message via MSN à sondo Envoyer un message via Yahoo à sondo Envoyer un message via Skype™ à sondo
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 :
ColS := format('%2d',[TdrawGrid(DbGrid1).col]);
Pouvez-vous m'aider à comprendre?

Merci d'avance.
sondo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2012, 12h46   #2
Paul TOTH
Expert Confirmé Sénior
 
Avatar de Paul TOTH
 
Homme Paul TOTH
Freelance
Inscription : novembre 2002
Messages : 4 430
Détails du profil
Informations personnelles :
Nom : Homme Paul TOTH
Âge : 43
Localisation : Réunion

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

Informations forums :
Inscription : novembre 2002
Messages : 4 430
Points : 10 844
Points : 10 844
ben c'est normal, TDBGrid n'est pas une TDrawGrid
__________________
Developpez.com: Mes articles, forum FlashPascal
Entreprise: Execute SARL
Produits : UPnP, RemoteOffice, FlashPascal
Embarcadero : Ile de la Réunion, Dephi, C++Builder, RADPHP...TVA à 8,5%
Paul TOTH est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2012, 14h22   #3
ShaiLeTroll
Expert Confirmé Sénior
 
Avatar de ShaiLeTroll
 
Homme
Développeur C++\Delphi
Inscription : juillet 2006
Messages : 9 202
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : France

Informations professionnelles :
Activité : Développeur C++\Delphi
Secteur : High Tech - Électronique et micro-électronique

Informations forums :
Inscription : juillet 2006
Messages : 9 202
Points : 13 255
Points : 13 255
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 :
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

Halte à la ségrégation des Cinémas, VO sur Paris, VF en Banlieue, Abonnement résilié !
ShaiLeTroll est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 04/10/2012, 14h36   #4
sondo
Membre régulier
 
Avatar de sondo
 
Inscription : août 2004
Messages : 443
Détails du profil
Informations forums :
Inscription : août 2004
Messages : 443
Points : 84
Points : 84
Envoyer un message via MSN à sondo Envoyer un message via Yahoo à sondo Envoyer un message via Skype™ à sondo
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 :
Dm_num := DbGrid1.Columns.Grid.Fields[TdrawGrid(DbGrid1).Col-1].AsString;
Erreur : Unsafe typecast of 'TDBGrid' to 'TDrawGrid'
Code :
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 :
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 :
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 :
Citation:
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'
sondo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2012, 15h32   #5
Paul TOTH
Expert Confirmé Sénior
 
Avatar de Paul TOTH
 
Homme Paul TOTH
Freelance
Inscription : novembre 2002
Messages : 4 430
Détails du profil
Informations personnelles :
Nom : Homme Paul TOTH
Âge : 43
Localisation : Réunion

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

Informations forums :
Inscription : novembre 2002
Messages : 4 430
Points : 10 844
Points : 10 844
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
Produits : UPnP, RemoteOffice, FlashPascal
Embarcadero : Ile de la Réunion, Dephi, C++Builder, RADPHP...TVA à 8,5%
Paul TOTH est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2012, 17h56   #6
Rayek
Modérateur
 
Avatar de Rayek
 
Homme
Développeur informatique
Inscription : mars 2005
Messages : 4 998
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 39
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 : 4 998
Points : 7 742
Points : 7 742
Citation:
Envoyé par sondo Voir le message
Code :
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 :
1
2
 
DM_NUM := LeComposantBaseDeDonnee.FieldByName('LE Nom Du champ').AsString;
__________________
Modérateur Delphi Combattez la brute
Aucune réponse aux sollicitations techniques par MP

Le guide du bon forumeur :__________
[Projet en cours] Des unités pour faciliter l'utilisation d'indy : EasyIndy 1.3
Rayek est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 00h37.


 
 
 
 
Partenaires

Hébergement Web