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 :

Problème de lancement de messages


Sujet :

Delphi

  1. #1
    Membre à l'essai
    Homme Profil pro
    Automaticien embarqué marine marchande
    Inscrit en
    Février 2014
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Automaticien embarqué marine marchande
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2014
    Messages : 37
    Points : 12
    Points
    12
    Par défaut Problème de lancement de messages
    Bonjour, je cherche à lancer des messages suivant une position GPS lue sur le COM,
    Avec ce programme, mes messages sont lancé un peu n'importe comment

    Je pense que le "playsound" dans une boucle While pose pb, j'ai tenté de sortir les playsound
    avec appel procedure, et avec un timer mais toujours le même pb.

    Y a t'il une autre façon de lancer des messages
    unit Unit1;

    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
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, CPort, CPortCtl, ComCtrls, jpeg, Menus, mmSystem;
     
    type
      TForm1 = class(TForm)
        ComPort1: TComPort;
        Image1: TImage;
        RadioGroup1: TRadioGroup;
        RichEdit_GLL: TRichEdit;
        Autorisation: TStaticText;
        Jete_D: TLabel;
        jete_c: TLabel;
        Interdiction: TStaticText;
        Vente_C_D: TOpenDialog;
        Vente_D_C: TOpenDialog;
        GroupBox1: TGroupBox;
        ListBox1: TListBox;
        Msg_SECU: TOpenDialog;
        Msg_Arr_C: TOpenDialog;
        Msg_Arr_D: TOpenDialog;
        Button1: TButton;
        Pass_Frontiere: TLabel;
        Timer1: TTimer;
     
        procedure ComPort1RxChar(Sender: TObject; Count: Integer);
        procedure RadioGroup1Click(Sender: TObject);
        procedure RichEdit_GLLChange(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
     
      private
        { Private declarations }
        MonMessage : String;
        procedure Vente_C_D;
        procedure Vente_D_C;
        procedure MSG_SECURITE;
        procedure MSG_Arr_C;
        procedure MSG_Arr_D;
     
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
      Tramecp : string;
      Val_Message : integer;
     
    implementation
     
    {$R *.dfm}
     
     
    procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);  // Gestion de lecture du port Com
    var NouveauMsg,MsgInt : string;
    PosEndTrame,Arrivee : integer;
    begin
    { *** Lecture PortCom *** }
        Comport1.ReadStr(NouveauMsg, Count);
        MonMessage := MonMessage + NouveauMsg;
        MonMessage := Uppercase (MonMessage);
        PosEndTrame := Pos(#13#10,  MonMessage);
          if PosEndTrame <> 0 then
             While PosEndTrame <> 0 do
              begin
                Tramecp := copy(MonMessage,0,PosEndTrame -1);
     
              MonMessage := Copy(MonMessage, PosEndTrame +1, Length(MonMessage));
              PosEndTrame := Pos(#13, MonMessage);
     
     
      {*** repérage de la position utile GLL ***}
     
                if (POS('$GPGLL', Tramecp)) <> 0 then
                        RichEdit_GLL.Lines.Add(Tramecp);
     
     
     
        { ***    Passage de la jetée  ***    }
     
       if (pos('5107.24',Tramecp))<> 0 then
                     begin
                      Timer1.Enabled := true;
                      Arrivee := 0;
                      RichEdit_GLL.Tag := 1;
                      Pass_Frontiere.Visible := false;
                      jete_d.Visible := true;
                     end;
     
               { *** Départ de D  ***}
     
     if (pos('5107.22',Tramecp)) and RichEdit_GLL.Tag = 1 then
                  begin
                    Interdiction.Visible := true;
                    Val_Message := 3;
                    //MSG_SECURITE;
                    //playSound(PChar(Msg_SECU.FileName),Handle,SND_SYNC);
                  end;
     
                   { *** Arrivée à D  ***}
     
     if (pos('5107.23',Tramecp))and Arrivee = 1  then
                  begin
                    Timer1.Enabled := true;
                    Val_Message := 5;
                    //MSG_Arr_D;
                    //playSound(PChar(Msg_Arr_D.FileName),Handle,SND_ASYNC);
                  end;
     
                  { ***      ***  }
       if (pos('5102.60',Tramecp)) and RichEdit_GLL.Tag = 1 then
                     begin
                       Timer1.Enabled := true;
                       Interdiction.Visible := false;
                       Autorisation.Visible := true;       // Autorisation de vente de Tabacs
     
                       Val_Message := 2;
                       //Vente_D_C;
                       //playSound(PChar(Vente_D_C.FileName),Handle,SND_ASYNC);
     
                     end;
     
           {  ***  (51°02'4 N)    ***}
     
     
              if (pos('5058.32',Tramecp))<> 0 then
                    begin
                       Timer1.Enabled := true;
                       Arrivee := 0;
                       RichEdit_GLL.Tag := 1;
                       Pass_Frontiere.Visible := false;
                       jete_c.Visible := true;
                       Autorisation.Visible := true;
                    end;
               { ***   ***}
     
     if (pos('5058.34',Tramecp)) and RichEdit_GLL.Tag = 1 then
                  begin
                   Val_Message := 3;
                   //MSG_SECURITE;
                   // playSound(PChar(Msg_SECU.FileName),Handle,SND_SYNC);
                  end;
     
                      {  ***   ***}
      if (pos('5101.60',Tramecp))and RichEdit_GLL.Tag = 1 then
                    begin
                       Timer1.Enabled := true;
                       Autorisation.Visible := false;
                       Interdiction.Visible := true;
                       Val_Message := 1;
                      // Vente_C_D;
                      //   playSound(PChar(Vente_C_D.FileName),Handle,SND_ASYNC);
     
                   end;
     
                   { ***   ***}
     
     if (pos('5058.33',Tramecp)) and arrivee = 1 then
                  begin
                   Timer1.Enabled := true;
                   Val_Message := 4;
                  //MSG_Arr_C;
                  // playSound(PChar(Msg_Arr_C.FileName),Handle,SND_ASYNC);
                  end;
     
     
        { *** Passage de la frontière  ***}
     
     if (pos('5102.40',Tramecp))<> 0 then
                   begin
                     Arrivee := 1;
                     jete_cal.Visible := false;
                     jete_dov.Visible := false;
                     Pass_Frontiere.Visible := true;
                     RichEdit_GLL.Tag := 0;
                     RichEdit_GLL.Clear ();
                  end;
        end;
    end;
    procedure TForm1.RadioGroup1Click(Sender: TObject);
    begin
     Case RadioGroup1.ItemIndex of
    0: Comport1.Connected := true;
    1: Comport1.Connected := false;
     end;
    end;
     
    procedure TForm1.Vente_C_D;
    begin
     // playSound(PChar(SON.FileName),Handle,SND_ASYNC);
      sndPlaySound('SON.wav', SND_ASYNC);
      Val_Message := 0;
      Timer1.Enabled := false;
    end;
     
    procedure TForm1.Vente_Douvres_Calais;
    begin
      // playSound(PChar(SON.FileName),Handle,SND_ASYNC);
       sndPlaySound('SON.wav', SND_ASYNC);
       Val_Message := 0;
       Timer1.Enabled := false;
    end;
     
    procedure TForm1.MSG_SECURITE;
    begin
     // playSound(PChar(SON.FileName),Handle,SND_ASYNC);
      sndPlaySound('SON.wav', SND_ASYNC);
      Val_Message := 0;
      Timer1.Enabled := false;
    end;
     
    procedure TForm1.MSG_Arr_Calais;
    begin
     // playSound(PChar(SON.FileName),Handle,SND_ASYNC);
     sndPlaySound('SON.wav', SND_ASYNC);
     Val_Message := 0;
     Timer1.Enabled := false;
    end;
     
    procedure TForm1.MSG_Arr_Douvres;
    begin
     // playSound(PChar(SON.FileName),Handle,SND_ASYNC);
     sndPlaySound('SON.wav', SND_ASYNC);
     Val_Message := 0;
     Timer1.Enabled := true;
    end;
     
    procedure TForm1.RichEdit_GLLChange(Sender: TObject);
    begin
    SendMessage(RichEdit_GLL.Handle,WM_VSCROLL,SB_BOTTOM,0);
    end;
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
     Vente_C_D;
    end;
     
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    case Val_Message of
    1: Vente_C_D;
    2: Vente_D_C;
    3: MSG_SECURITE;
    4: MSG_Arr_C;
    5: MSG_Arr_D;
    end;
    end;
    end.

  2. #2
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    CORRECTION:
    que ce soit avec PlaySound ou sndPlaySound, j'ai un fonctionnement asynchrone avec le flag SND_ASYNC.

    Si tu enlèè_ves ces parties là, ton programme ne bloque pas?
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  3. #3
    Membre à l'essai
    Homme Profil pro
    Automaticien embarqué marine marchande
    Inscrit en
    Février 2014
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Automaticien embarqué marine marchande
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2014
    Messages : 37
    Points : 12
    Points
    12
    Par défaut
    Bonjour,
    J'ai trouvé la solution, mon code était mauvais, en y ajoutant des variables, il tourne correctement avec SND_ASYNCH

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

Discussions similaires

  1. [Eclipse 3.0.1]problème de lancement d'eclipse
    Par sehaba dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 05/04/2005, 10h09
  2. [Plugin] Problème de lancement
    Par relivio dans le forum Eclipse Platform
    Réponses: 1
    Dernier message: 03/08/2004, 14h34
  3. [Kylix] Problème de lancement
    Par jaguarwan dans le forum EDI
    Réponses: 1
    Dernier message: 21/02/2004, 22h40
  4. [Install] Problème de lancement sous debian sid
    Par SoaR245 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 18/02/2004, 10h01
  5. problème envoie d'un message postcommand()
    Par semenzato dans le forum MFC
    Réponses: 4
    Dernier message: 13/01/2004, 17h26

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