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
| Unit1.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CPortCtl"
#pragma link "CPort"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// déclarations de nos variables
AnsiString pass;
// On remonte d'une ligne sur notre table
Table1->Last();
// On récupère la valeur de chaque colonne
pass = Table1->FieldByName("pass")->AsString;
// On affiche ces valeurs dans les zones de texte
Edit1->Text = pass;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComPort1RxChar(TObject *Sender, int Count)
{
AnsiString Str;
ComPort1->ReadStr(Str, Count);
Edit2->Text=Str;
}
//---------------------------------------------------------------------------
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <DB.hpp>
#include <DBTables.hpp>
#include "CPortCtl.hpp"
#include <ExtCtrls.hpp>
#include "CPort.hpp"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTable *Table1;
TDatabase *Database1;
TEdit *Edit1;
TLabel *Label1;
TLabel *Label2;
TEdit *Edit2;
TComLed *ComLed1;
TComLed *ComLed2;
TLabel *Label3;
TLabel *Label4;
TButton *Button1;
TButton *Button2;
TQuery *Query1;
TDataSource *DataSource1;
TTimer *Timer1;
TComPort *ComPort1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
//void __fastcall Timer1TimerTimer(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall ComPort1RxChar(TObject *Sender, int Count);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif |
Partager