Explorer les Livres électroniques
Catégories
Explorer les Livres audio
Catégories
Explorer les Magazines
Catégories
Explorer les Documents
Catégories
begin
Application.Initialize;
Form2 := Tform2.Create(Application);
Form2.Show;
Form2.Update;
Application.Title := 'Marine Adventures Order Entry';
Application.HelpFile := 'MASTAPP.HLP';
Application.CreateForm(TMainForm, MainForm);
Form2.Hide;
Form2.Free;
Application.Run;
unit instanz_laden;
interface
implementation
uses windows,Dialogs,sysutils;
var mHandle: THandle; // Mutexhandle
Initialization
mHandle := CreateMutex(nil,True,'XYZ');
if GetLastError = ERROR_ALREADY_EXISTS then begin //
L'application est déjà lancée
showMessage(' L''application est déjà lancée !!!!!');
halt;
end;
begin
application.title:=a;
form1.Caption:=a;
for i:=1 to (length(a)-1) do
a[i]:=application.title[i+1];
a[length(a)]:=application.title[1];
end;
RichEdit1.SelectAll;
Copier – coller
Les messages:
Valeur Signification
mtWarning Une boîte de message
contenant un signe point
d'exclamation jaune.
mtError Une boîte de message
contenant un signe de stop
rouge.
mtInformation Une boîte de message
contenant un "i" bleu.
mtConfirmation Une boîte de message
contenant un point
d'interrogation vert.
mtCustom Une boîte de message ne
contenant pas d'image. Le
titre de la boîte de
dialogue est le nom du
fichier exécutable de
l'application.
Showmessage une boite de message simple.
RadioGroup
Application.HelpCommand(HELP_CONTENTS, 0);
StartPos := 0;
modification du type:
strtofloat(edit1.Text)
strtoint(edit1.text)
inttostr(x) ext…..
Remarque:le type de float c'est extended.
begin
c:= TCanvas.Create;
c.Handle:= GetWindowDC (GetDesktopWindow);
try
r:= Rect(0,0,screen.width,screen.height);
Bild.Width:=screen.Width;
Bild.Height:=screen.Height;
Bild.Canvas.CopyRect(r, c, r);
finally
ReleaseDC(0, c.handle);
c.Free;
end;
end;
begin
c:= TCanvas.Create;
c.Handle:= GetWindowDC (GetDesktopWindow);
h:=GetForeGroundWindow;
if h<>0 then
GetWindowRect(h, t);
try
r:= Rect(0,0,t.Right-t.left,t.Bottom-t.Top);
Bild.Width:=t.Right-t.left;
Bild.Height:=t.Bottom-t.Top;
Bild.Canvas.CopyRect(r, c, t);
finally
ReleaseDC(0, c.handle);
c.Free;
end;
end;
Ouvrir/fermer le lecteur de CD
uses mmsystem;
begin
{ make it upper case }
if Drive in ['a'..'z'] then Dec(Drive, $20);
{ make sure it's a letter }
if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');
{ turn off critical errors }
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
{ drive 1 = a, 2 = b, 3 = c, etc. }
if DiskSize(Ord(Drive) - $40) = -1 then
Result := False
else
Result := True;
finally
{ restore old error mode }
SetErrorMode(ErrorMode);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if DiskInDrive('a')=false then
begin
ShowMessage('Drive not ready');
end;
end;
2-Internet :
Envoyer une-mail
Uses WinTypes, ShellAPI;
begin
ShellExecute( 0, Nil, PChar('mailto:offset@multimania.com'),Nil,
Nil, SW_NORMAL );
end;
begin
if (VarIsEmpty(IE) ) then
begin
IE := CreateOleObject('InternetExplorer.Application');
IE.Visible := true;
IE.Navigate(aURL);
end
else
begin
WinHanlde := FindWIndow('IEFrame', nil);
if (0 <> WinHanlde) then
begin
IE.Navigate(aURL);
SetForegroundWindow(WinHanlde);
end
else
ShowMessage('Can''t open IE !');
end;
end;
3-Windows :
WinExec('rundll32.exe shell32.dll,Control_RunDLL
sysdm.cpl',SW_SHOWNORMAL);
begin
x:=Screen.Width;
y:=Screen.Height;
Label1.Caption:='x-Auflösung: '+IntToStr(x);
Label2.Caption:='y-Auflösung: '+IntToStr(y);
end;
function NewRes(XRes,YRes:DWord):integer;
var
DevMode:TDeviceMode;
begin
EnumDisplaySettings(nil, 0, DevMode);
DevMode.dmFields:=DM_PELSWIDTH or DM_PELSHEIGHT;
DevMode.dmPelsWidth:=XRes;
DevMode.dmPelsHeight:=YRes;
Result:=ChangeDisplaySettings(DevMode, 0);
end;
4-Base de données :
Base de données :
Collection de données dans des tables.
Requête :
Moyen de rechercher des données dans des tables. Une requête
peut s'appliquer à une ou à plusieurs tables.
Insertion
begin
table1.Open;
table1.insert;
table1.FieldByName('cfo').AsString:=(edit1.text);
table1.FieldByName('nfo').AsString:=ansiuppercase(edit2.text);
table1.FieldByName('pays').AsString:= ansiuppercase(EDIT8.text);
table1.post;
end;
Recherche:
var
rech:string;
begin
rech :=ansiuppercase ( inputbox('Recherche','Entrer le code
','1'));
If not table1.FindKey([rech]) then
messagedlg('Enregistrement introuvable',mtinformation,[mbok],0);
End;
var
rech:string;
x:boolean;
begin
rech:= ansiuppercase (inputbox('Recherche','Entrer le nom de la
fournisseur',''));
table1.First;
x:=false;
while (not table1.Eof) do
if table1.FieldValues ['nfo']=rech then
begin
x:=true;
break;
end
else
table1.next;
if not x then
messagedlg('champ introuvable',mtinformation,[mbok],0);
end;
Begin
if messagedlg( 'Voulez-vous vraiment supprimer
',mtconfirmation,[mbyes,mbno], 0)=mryes
then
table1.Delete;
end ;
Mot de passe
var
i:integer;
…
procedure TForm1.FormCreate(Sender: TObject);
begin
I:=0;
End;
…
procedure TForm1.Button1Click(Sender: TObject);
Begin
if i=3 then
begin
showmessage('Vous-vous étés trompé de mot de passe 3 fois, le
programme va s''arrêter maintenant ..');
form1.Close;
end
else
IF TABLE1.FindKey([edit1.text])
then
begin
form1.hide;
form2.show;
end
else
If messagedlg ('Mot de passe incorect? voulez-vous réessayer
',mtconfirmation,[mbyes,mbno],0)=mryes
then
begin
edit1.clear;
end
else begin
form1.close;
end;
i:=i+1;
end;
begin
table1.Open;
table1.First;
table1.Filter:='nfo=''B*''';
table1.Filtered:= true;
end;
ignorée le filtre
begin
table1.Open;
table1.First;
table1.Filtered:= false;
end;
----------------------------------------------------------------
var
x:integer;
begin
table1.First;
x:= strtoint(edit1.text);
table1.MoveBy(x-1);
end
Shift: TShiftState);
begin
if Key=VK_LEFT then
begin
{ici vous mettez le traitement à faire}
end;
end;
Liste des valeurs possibles pour Key:
----------------------------------------------------------------
RichEdit1.Clear;
NomFichier := 'Sans titre.txt';
StatusBar1.Panels[0].Text := NomFichier;
----------------------------------------------------------------
var
x:integer;
begin
for x:=4 to 2000 do
memo1.Lines.Add(inttostr(x));
end;
----------------------------------------------------------------
1) Application.ShowMainForm := False; Pour masquer la fiche
principale au démarrage.
2) Form1.Caption:=Application. Title;
----------------------------------------------------------------
Application.Terminate; //Fin de programme
----------------------------------------------------------------
if OpenDialog1.Execute then
begin
MediaPlayer1.FileName := OpenDialog1.FileName;
MediaPlayer1.Open;
MediaPlayer1.Display := Form1;
MediaPlayer1.DisplayRect := RECT(10,10,200,200);
end;
----------------------------------------------------------------
06-Question
Les propriétés :
Exemple :
Flat: Détermine si les boutons ont un aspect tridimensionnel
avec des bordures ou un aspect bidimensionnel sans bordure.
----------------------------------------------------------------
ShowAccelChar
Label1.ShowAccelChar := False;
Label1.Caption := 'Une esperluète & apparaît ici';
Le résultat : 'Une esperluète & apparaît ici
Label1.ShowAccelChar := False;
Label1.Caption := 'Une esperluète & apparaît ici';
Le résultat : 'Une esperluète apparaît ici
Tag:Stocke une valeur entière dans un composant.
TopIndex: pour ListBox,Spécifie l'indice de l'élément
apparaissant en haut de la boîte liste.
Modification d'un menu Form1.Menu := SecondMenu;
07-RACCOURCIS DELPHI
if trim(dbedit6.text)='' then
begin
codeEstSaisie:=false;
Showmessage('Le Code Doit avoir une valeur');
Intervalle de table
end;
end;
----------------------------------------------------------------
with Customer do
begin
EditRangeStart;
FieldByName('Company').AsString := Edit1.Text;
{Définit l'intervalle de début en fonction du texte du
composant Edit1 }
EditRangeEnd;
FieldByName('Company').AsString := Edit2.Text;
end;
----------------------------------------------------------------
property Bof: Boolean;
Indique si une requête est positionnée au début de l'ensemble de
données.
Utilisez la propriété BOF pour déterminer si une requête est
positionnée au début de l'ensemble de données.
----------------------------------------------------------------
Le code suivant affiche une boîte de dialogue si le travail
d'impression a été abandonné :
if Printer.Aborted then
MessageDlg('Le travail d''impression n''a pas terminé
l''impression', mtInformation, [mbOK], 0);
----------------------------------------------------------------
property HintPause: Integer;
Spécifie l'intervalle de temps qui s'écoule avant que
n'apparaisse le conseil du contrôle quand l'utilisateur a placé
le curseur de la souris au-dessus du contrôle ou de l'élément de
menu
Description :
Utilisez HintPause pour modifier la durée par défaut de 500 ms
ou 1/2 seconde, définie dans le constructeur. Lors de
l'affectation d'une valeur à HintPause l'intervalle doit être
exprimé en millisecondes. Le conseil affiché à la fin de
l'intervalle est spécifié dans la propriété Hint
Exp :
procedure TForm1.FormActivate(Sender: TObject);
var i:integer;
begin
application.HintPause:=0;
end;
----------------------------------------------------------------
procedure TForm1.Panel2MouseMove(Sender: TObject; Shift:
TShiftState; X,
Y: Integer);
begin
{Si on bouge la souris avec la touche gauche appuyée (ssLeft)
alors on redimensionne
le Panel1. Le Panel3 qui est Align=alClient suivra
automatiquement}
if ssLeft in Shift then Panel1.Width:=Panel1.Width+X;
end;
----------------------------------------------------------------
procedure TForm1.Button3Click(Sender: TObject);
begin
Memo2.Parent:=Panel1;
end;
----------------------------------------------------------------
procedure TForm1.Button2Click(Sender: TObject);
begin
MessageBeep(MB_ICONASTERISK);
showmessage('R2514487');
end;
Autre :
MessageBeep(MB_OK);
MessageBeep(MB_ICONHAND);
MessageBeep(MB_ICONQUESTION);
MessageBeep($FFFFFFFF) ;
----
dbcdt.Histor_equip.Filter:='repere='+Quotedstr(edit1.text);
table5.Filter:=('craft ='''+edit2.Text+'''');
----------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
DateSeparator := '-';
ShortDateFormat := 'm/d/yyyy';
Label1.Caption := DateToStr(Date);
end;
----------------------------------------------------------------
Trim :Fonction
supprime les caractères de contrôle et les espaces se trouvant
en début et en fin de chaîne.
Exp: if length(trim(Edit1.text))=16 then showmessage(‘ Hallo ‘);
----------------------------------------------------------------
var
Form1: TForm1;
i: Byte;
…
----------------------------------------------------------------
const crMyCursor = 5;
crAutreCurseur = 6;
// default drawing
DBGrid1.DefaultDrawDataCell (OutRect, Column.Field, State);
End;
----------------------------------------------------------------
Label1.wordWrap :=true ;
Description
nitialisez WordWrap à True pour permettre au libellé d'afficher
plusieurs lignes de texte. Quand WordWrap est à True, tout texte
trop long pour la largeur du contrôle libellé passe à la ligne
suivante au niveau de la marge droite et continue sur les lignes
suivantes.
----------------------------------------------------------------
Inc(valeur) Incrémente une valeur ordinale (X) de 1 ou de N.
Exemple :
var
IntVar: Integer;
LongintVar: Longint;
begin
Inc(IntVar); { IntVar := IntVar + 1 }
Inc(LongintVar, 5); { LongintVar := LongintVar + 5 }
end;
----------------------------------------------------------------
procedure TFOT2date.SpeedButton1Click(Sender: TObject);
var
debut,fin:tdate;
begin
debut:=strtodate(edit1.Text);
fin:=strtodate(edit2.text);
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM Ot where date_ot>=:date_d and
date_ot<=:date_f');
Query1.ParamByName('date_d').asdate:=debut;
Query1.ParamByName('Date_f').asdate:=fin;
Query1.open;
end;
----------------------------------------------------------------
Halt :Exécute une fin anormale d'un programme.
Description :
La procédure Halt exécute une fin anormale d'un programme et
renvoie le contrôle au système d'exploitation. Pour exécuter une
fin normale d'une application non-console VCL Delphi, appelez
Application.Terminate. Exitcode est une expression facultative
qui indique le code de sortie du programme.
------
Déplasment de la fiche par fléche....
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
vk_UP : Self.Top := Self.Top - 10;
vk_DOWN : Self.Top := Self.Top + 10;
vk_LEFT : Self.Left := Self.Left - 10;
vk_RIGHT : Self.Left := Self.Left + 10;
end;
uses ComObj;
…
procedure TForm1.Button1Click(Sender: TObject);
var
excel:Variant;
i:Byte;
begin
try
excel:=CreateOleObject('Excel.Application');
except
ShowMessage('Excel n''a pas pu être lancé !');
exit;
end;
excel.Visible:=true;
table1.First;
i:=1;
excel.Workbooks.Add;
while not table1.Eof do
begin
excel.Cells[i,1].Value:=Table1code.Value;
excel.Cells[i,2].Value:=Table1designation.Value ;
excel.Cells[i,3].Value:=Table1Quentit.Value ;
table1.Next;
i:=i+1;
end;
end;
var
region: HRgn;
begin
region:=CreateEllipticRgn(1,1,200,200);
end;
begin
iX :=200 ;
begin
Brush.Color := RGB(Ix,0,row);
end;
Lancement de calculatrice :
ShellExecute(0,PChar('open)...,)'
Ouvrir un document :
ShellExecute(0,'OPEN','C:\Temp\Monfichier.txt', Nil, Nil,
SW_SHOW;)
Imprimer un document :
ShellExecute(0,'PRINT','C:\Temp\Monfichier.doc', Nil, Nil,
SW_SHOW;)
Exemple de raccourci:
Cible = "C:\Program Files\Microsoft IntelliPoint\dplaunch.exe"
Mouse CPL
Démarrer dans = "C:\Program Files\Microsoft IntelliPoint"\
Exécuter : Fenêtre normale
L'appel sera :
ShellExecute(
Application.Handle,
'open,'
'C:\Program Files\Microsoft IntelliPoint\dplaunch.exe','Mouse
CPL,'
'C:\Program Files\Microsoft IntelliPoint,'\SW_SHOW );
ShellExecute(0,nil, PChar(GetEnvironmentVariable('ComSpec')),
PChar('/C Net View > Resultat.txt'), nil, 0) ;
Le résultat de la fonction ShellExecute est un entier. S'il est
inférieur ou égal à 32, l'exécution a échoué. S'il est
strictement supérieur à 32, le processus a été lancé
correctement. Pour surveiller la fin du processus engendré, il
est conseillé d'utiliser CreateProcess au lieu de ShellExecute.
Les codes d'erreur de ShellExecute sont symboliques. Ils
correspondent à ceci sur une cible Win32 :
If (Code<=32) Then
//Affichage du message d'erreur "hard", AVEC levée d'exception.
//Remplacer par RaiseLastWin32Error sur les anciennes versions
de Delphi.
RaiseLastOSError;
End;
Par exemple pour afficher une valeur avec deux chiffres après la
virgule :
Var f:Real;
begin
f:=12345.6789;
ShowMessage(FloatToStrf(f,ffFixed,8,2));
ShowMessage(FormatFloat('0.00',f));
ShowMessage(Format('%8.2f',[f]));
end;
Fonction Trunc(X:Extended):Integer;
Trunc ajuste à l'entier le plus petit. Exemples:
Trunc(1.2) donne 1
Trunc(1.9) donne 1
Trunc(-1.4) donne -1
Fonction Round(X:Extended):Integer;
Round arrondi à l'entier le plus proche, dans le cas ou la
valeur est juste entre deux entiers, c'est l'entier pair qui est
choisi. Exemples:
Round(1.2) donne 1
Round(1.9) donne 2
Round(1.5) donne 2
Round(2.5) donne 2
Round(2.500001) donne 3
Round(-1.4) donne -1
Round(-1.5) donne -2
...
Initialization
DecimalSeparator;'.'=:
end.
Exemple:
showMessage(floatToStr(SimpleRoundTo(1.235,-2))) ;
// Affiche 1.24
Si cette fonction n'est pas disponible dans votre version de
Delphi, vous pouvez utiliser la fonction suivante :
uses
Math ;
Exemples:
memo1.Lines.Add(floatToStr(arrondir(12,2))) ;
memo1.Lines.Add(floatToStr(arrondir(13.59,1))) ;
memo1.Lines.Add(floatToStr(arrondir(0.1,5))) ;
memo1.Lines.Add(floatToStr(arrondir(0.14444444,3))) ;
memo1.Lines.Add(floatToStr(arrondir(1.5,0))) ;
memo1.Lines.Add(floatToStr(arrondir(1.54345678,1))) ;
memo1.Lines.Add(floatToStr(arrondir(1.54345678,2))) ;
memo1.Lines.Add(floatToStr(arrondir(1.54345678,3))) ;
memo1.Lines.Add(floatToStr(arrondir(1.54345678,4))) ;
on obtient:
22 /2,,1/0,2 /0,200 /2 /2,1 / 2,10/ 2,10, / 2,10,1
Syntaxe Delphi:
function Power(const Base, Exponent: Extended): Extended;
Description
Power élève Base à n'importe quelle puissance. Pour les
exposants fractionnels ou supérieurs à MaxInt, le paramètre Base
doit être supérieur à 0.
var
MaDate: TDate;
Jour, Mois, Annes: Word;
begin
//Jour, Mois et Annee doit être une date valide
//Pour encoder:
MaDate := EncodeDate(Annee,Mois,Jour);
//Pour décoder
DecodeDate(MaDate, Annee, Mois, Jour);
end;
CB_SETDROPPEDWIDTH
wParam = (WPARAM) wWidth, // width of list box, in pixels
lParam = 0, // not used, must be zero
----------------------------------------------------------------
----------------------------------------------------------------
End.
Raccourci ctrl+P :
if (ssCtrl in Shift)
then
begin
case char(key) of
'P', 'p': AboutBox.ShowModal;
'N','n' :close;
end;
end;
end;
----------------------------------------------------------------