Einbindung eigener Bibliotheken

Die Sicherheitsabfragen sollen in eine eigene Bibliothek geschrieben werden, damit man sie dann für verschiedene Projekte einbinden kann.

MyTools.cpp

MyTools.cpp wird erstellt mittels Datei-Neu-Unit

//---------------------------------------------------------------------------
 
#pragma hdrstop
 
#include "MyTools.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
 
 
void checkFloatInput(TEdit *Edit, System::WideChar &Key)
{
  //8...Backspace
  //0...Leer
  if (!((Key>='0')&&(Key<='9')||(Key==',')||(Key==8)||(Key=='-')))
	 {
		 Key=0;
	 }
 if (Key==',' && Edit->Text.Pos(",")!=0)
 {  //verhindert 2 Kommas!
	  Key=0;
 }
 if (Key=='-' && Edit->Text!="") {     //erlaubt ein Minus an erster Stelle! (negative Zahlen)
  Key=0;
  }
}
 
void checkIntegerInput(TEdit *Edit, System::WideChar &Key)
{
  //8...Backspace
  //0...Leer
  if (!((Key>='0')&&(Key<='9')||(Key==8)||(Key=='-')))
	 {
		 Key=0;
	 }
 
 if (Key=='-' && Edit->Text!="") {     //erlaubt ein Minus an erster Stelle! (negative Zahlen)
  Key=0;
  }
}
 
void checkPositiveIntegerInput(TEdit *Edit, System::WideChar &Key)
{
  //8...Backspace
  //0...Leer
  if (!((Key>='0')&&(Key<='9')||(Key==8)))
	 {
		 Key=0;
	 }
}

Header-Datei MyTools.h

In die Header-Datei deklariert man die Funktionen, welche sich in MyTools.cpp befinden:

//---------------------------------------------------------------------------
#ifndef MyToolsH
#define MyToolsH
 
void checkFloatInput(TEdit *Edit, System::WideChar &Key);
void checkIntegerInput(TEdit *Edit, System::WideChar &Key);
void checkPositiveIntegerInput(TEdit *Edit, System::WideChar &Key);
 
//---------------------------------------------------------------------------
#endif

Aufruf in Unit1.cpp

//Einbinden der Header-Datei
#include "MyTools.h"
 
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, System::WideChar &Key)
{
	//Aufruf der Funktion checkPositiveIntegerInput
	checkPositiveIntegerInput(Edit1, Key);
}