Accueil > > > DRAG'N DROP ENTRE 2 CONTRÔLES DE MÊME NATURE
DRAG'N DROP ENTRE 2 CONTRÔLES DE MÊME NATURE
Information sur la source
Description
Démonstration du Tirer/Lâcher (drag and drop) entre : -> 2 composants TList -> au sein d'un même composant TList Ce code inclut aussi une fonction de recherche de chaîne selon un masque défini par l'utilisateur, en utilisant les caractères jokers ? et *. Ce code n'est pas de moi et je ne me souviens plus de son auteur.
Source
- //
- // Auteur : Delphiprog
- // E-mail :
- // Internet : http://www.delphiprog.fr.fm
- // Date création : 29/08/2002
- // Date révision : 13/03/2003
- {
- }
- // Objet :
- { - Démo de recherche de chaînes dans d'autres chaînes
- à l'aide d'un masque. Le code de recherche de chaînes selon un modèle
- (pattern) n'est pas de moi.
- - utilisation du drag'n drop entre deux composants TListBox et
- dans une même TListBox, dans un sens comme dans l'autre.
- }
- // Remarques :
- {
- }
- unit UDragDropDemoForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls;
-
- type
- TDragDropDemoForm = class(TForm)
- btnVerifyMatching: TButton;
- lbxChoix: TListBox;
- Edit1: TEdit;
- chbxCasse: TCheckBox;
- Label1: TLabel;
- Label2: TLabel;
- lbxSelectionne: TListBox;
- Label3: TLabel;
- StatusBar1: TStatusBar;
- Label4: TLabel;
- procedure btnVerifyMatchingClick(Sender: TObject);
- procedure lbxSelectionneDragOver(Sender, Source: TObject; X, Y: Integer;
- State: TDragState; var Accept: Boolean);
- procedure lbxSelectionneDragDrop(Sender, Source: TObject; X, Y: Integer);
- procedure lbxSelectionneStartDrag(Sender: TObject;
- var DragObject: TDragObject);
- private
- { Déclarations privées }
- public
- { Déclarations publiques }
- end;
-
- var
- DragDropDemoForm: TDragDropDemoForm;
- //Position de départ d'une opération de Drag'n drop
- StartPos,
- //index de l'élément de destination du drag'n drop
- EndPos: integer;
-
- implementation
-
- {$R *.DFM}
-
- ResourceString
- sStringsFound = '%d chaîne(s) trouvée(s)';
-
- {-----------------------------------------------------------------------------
- Procedure: MatchStrings
- Author: ???
- Date: 16-janv.-2003
- Arguments: source, pattern: string
- Result: Boolean
- Objet : Rechercher dans source si le modéle pattern transmis
- correspond.
- -----------------------------------------------------------------------------}
-
- function MatchStrings(source, pattern: string): Boolean;
- var
- pSource: array[0..255] of Char;
- pPattern: array[0..255] of Char;
-
- function MatchPattern(element, pattern: PChar): Boolean;
-
- function IsPatternWild(pattern: PChar): Boolean;
- begin
- Result := StrScan(pattern, '*') <> nil;
- if not Result then
- Result := StrScan(pattern, '?') <> nil;
- end;
-
- begin
- if 0 = StrComp(pattern, '*') then
- Result := True
- else
- if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
- Result := False
- else
- if element^ = Chr(0) then
- Result := True
- else
- begin
- case pattern^ of
- '*':
- if MatchPattern(element, @pattern[1]) then
- Result := True
- else
- Result := MatchPattern(@element[1], pattern);
- '?': Result := MatchPattern(@element[1], @pattern[1]);
- else
- if element^ = pattern^ then
- Result := MatchPattern(@element[1], @pattern[1])
- else
- Result := False;
- end;
- end;
- end;
- begin
- StrPCopy(pSource, source);
- StrPCopy(pPattern, pattern);
- Result := MatchPattern(pSource, pPattern);
- end;
-
- procedure TDragDropDemoForm.btnVerifyMatchingClick(Sender: TObject);
- var
- i: integer;
- begin
- with LbxChoix do
- //Parcourir la liste
- for i := 0 to Items.Count - 1 do
- begin
- //Déselectionner chaque élément
- Selected[i] := False;
- //S'il faut vérifier la casse des caractères...
- if chbxCasse.Checked then
- begin
- //...transmettre les chaines tel quel
- if MatchStrings(Items[i], Edit1.Text) then
- Selected[i] := True;
- end
- else
- //...ou effectuer la comparaison sur les majuscules
- if MatchStrings(UpperCase(Items[i]), UpperCase(Edit1.Text)) then
- Selected[i] := True;
- end;
- Label2.Caption := Format(sStringsFound, [lbxChoix.SelCount]);
- end;
-
- procedure TDragDropDemoForm.lbxSelectionneDragOver(Sender, Source: TObject; X, Y: Integer;
- State: TDragState; var Accept: Boolean);
- begin
- //Accepter l'opération SSI le contrôle de départ est un TListBox
- Accept := (Source is TListBox) and (TListBox(Source).ItemIndex <> -1);
- end;
-
- procedure TDragDropDemoForm.lbxSelectionneDragDrop(Sender, Source: TObject; X, Y: Integer);
- var
- { utilisé pour ItemAtPos pour connaître l'indice de l'élément
- sur lequel on va lâcher un élément }
- APoint: TPoint;
- begin
- APoint.X := X;
- APoint.y := Y;
- //Si l'élément tiré est issu d'une autre listbox...
- if Sender <> Source then
- begin
- //Insérer l'élément à la position courante
- with TListBox(Sender) do
- Items.Insert(ItemAtPos(APoint, True),
- TListBox(Source).Items[TListBox(Source).ItemIndex]);
- //et le supprimer de la ListBox d'origine
- with TListBox(Source) do
- Items.Delete(ItemIndex);
- end
- else
- //Un élément va être relâché sur la même ListBox
- with TListBox(Source) do
- begin
- //Calcul de l'indice de l'élément de destination
- EndPos := ItemAtPos(APoint, True);
- //Déplacer l'élément de son ancienne position à la nouvelle
- Items.Move(StartPos, EndPos);
- end;
- end;
-
- procedure TDragDropDemoForm.lbxSelectionneStartDrag(Sender: TObject;
- var DragObject: TDragObject);
- begin
- { Déterminer la position de départ de
- l'opération de tirer/Lâcher }
- StartPos := TListBox(Sender).ItemIndex;
- end;
-
- end.
//
// Auteur : Delphiprog
// E-mail :
// Internet : http://www.delphiprog.fr.fm
// Date création : 29/08/2002
// Date révision : 13/03/2003
{
}
// Objet :
{ - Démo de recherche de chaînes dans d'autres chaînes
à l'aide d'un masque. Le code de recherche de chaînes selon un modèle
(pattern) n'est pas de moi.
- utilisation du drag'n drop entre deux composants TListBox et
dans une même TListBox, dans un sens comme dans l'autre.
}
// Remarques :
{
}
unit UDragDropDemoForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TDragDropDemoForm = class(TForm)
btnVerifyMatching: TButton;
lbxChoix: TListBox;
Edit1: TEdit;
chbxCasse: TCheckBox;
Label1: TLabel;
Label2: TLabel;
lbxSelectionne: TListBox;
Label3: TLabel;
StatusBar1: TStatusBar;
Label4: TLabel;
procedure btnVerifyMatchingClick(Sender: TObject);
procedure lbxSelectionneDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure lbxSelectionneDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure lbxSelectionneStartDrag(Sender: TObject;
var DragObject: TDragObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
DragDropDemoForm: TDragDropDemoForm;
//Position de départ d'une opération de Drag'n drop
StartPos,
//index de l'élément de destination du drag'n drop
EndPos: integer;
implementation
{$R *.DFM}
ResourceString
sStringsFound = '%d chaîne(s) trouvée(s)';
{-----------------------------------------------------------------------------
Procedure: MatchStrings
Author: ???
Date: 16-janv.-2003
Arguments: source, pattern: string
Result: Boolean
Objet : Rechercher dans source si le modéle pattern transmis
correspond.
-----------------------------------------------------------------------------}
function MatchStrings(source, pattern: string): Boolean;
var
pSource: array[0..255] of Char;
pPattern: array[0..255] of Char;
function MatchPattern(element, pattern: PChar): Boolean;
function IsPatternWild(pattern: PChar): Boolean;
begin
Result := StrScan(pattern, '*') <> nil;
if not Result then
Result := StrScan(pattern, '?') <> nil;
end;
begin
if 0 = StrComp(pattern, '*') then
Result := True
else
if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
Result := False
else
if element^ = Chr(0) then
Result := True
else
begin
case pattern^ of
'*':
if MatchPattern(element, @pattern[1]) then
Result := True
else
Result := MatchPattern(@element[1], pattern);
'?': Result := MatchPattern(@element[1], @pattern[1]);
else
if element^ = pattern^ then
Result := MatchPattern(@element[1], @pattern[1])
else
Result := False;
end;
end;
end;
begin
StrPCopy(pSource, source);
StrPCopy(pPattern, pattern);
Result := MatchPattern(pSource, pPattern);
end;
procedure TDragDropDemoForm.btnVerifyMatchingClick(Sender: TObject);
var
i: integer;
begin
with LbxChoix do
//Parcourir la liste
for i := 0 to Items.Count - 1 do
begin
//Déselectionner chaque élément
Selected[i] := False;
//S'il faut vérifier la casse des caractères...
if chbxCasse.Checked then
begin
//...transmettre les chaines tel quel
if MatchStrings(Items[i], Edit1.Text) then
Selected[i] := True;
end
else
//...ou effectuer la comparaison sur les majuscules
if MatchStrings(UpperCase(Items[i]), UpperCase(Edit1.Text)) then
Selected[i] := True;
end;
Label2.Caption := Format(sStringsFound, [lbxChoix.SelCount]);
end;
procedure TDragDropDemoForm.lbxSelectionneDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
//Accepter l'opération SSI le contrôle de départ est un TListBox
Accept := (Source is TListBox) and (TListBox(Source).ItemIndex <> -1);
end;
procedure TDragDropDemoForm.lbxSelectionneDragDrop(Sender, Source: TObject; X, Y: Integer);
var
{ utilisé pour ItemAtPos pour connaître l'indice de l'élément
sur lequel on va lâcher un élément }
APoint: TPoint;
begin
APoint.X := X;
APoint.y := Y;
//Si l'élément tiré est issu d'une autre listbox...
if Sender <> Source then
begin
//Insérer l'élément à la position courante
with TListBox(Sender) do
Items.Insert(ItemAtPos(APoint, True),
TListBox(Source).Items[TListBox(Source).ItemIndex]);
//et le supprimer de la ListBox d'origine
with TListBox(Source) do
Items.Delete(ItemIndex);
end
else
//Un élément va être relâché sur la même ListBox
with TListBox(Source) do
begin
//Calcul de l'indice de l'élément de destination
EndPos := ItemAtPos(APoint, True);
//Déplacer l'élément de son ancienne position à la nouvelle
Items.Move(StartPos, EndPos);
end;
end;
procedure TDragDropDemoForm.lbxSelectionneStartDrag(Sender: TObject;
var DragObject: TDragObject);
begin
{ Déterminer la position de départ de
l'opération de tirer/Lâcher }
StartPos := TListBox(Sender).ItemIndex;
end;
end.
Conclusion
Ce code n'implémente le Tirer/Lâcher que d'un seul élément à la fois. Delphi 4 et +. Utilisable avec l'édition personnelle de Delphi.
Fichier Zip
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[HS] CHROME 6 + MOI = COUP DE GUEULE ![HS] CHROME 6 + MOI = COUP DE GUEULE ! par JeremyJeanson
Attention, le poste qui suit n'est pas la complainte d'une personne : Qui n'aime pas Chrome. D'un anti Google. D'un développeur qui a un poil énorme dans la main. Ceux qui me fréquentent savent que je change de navigateur favori tous les 2 ou 3 mois afin ...
Cliquez pour lire la suite de l'article par JeremyJeanson [WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7[WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7 par Audrey
Lors de la réalisation de ma 2ème application Windows Phone 7, j'ai souhaité utiliser un WrapPanel pour afficher plusieurs photos. Mais le contrôle WrapPanel ne fait pas parti de la liste des contrôles inclus dans le SDK de la version Beta des outils pour...
Cliquez pour lire la suite de l'article par Audrey [WP7] BESOIN D'AVOIR DES DONNéES EN CACHE[WP7] BESOIN D'AVOIR DES DONNéES EN CACHE par Nicolas
Les développeurs ASP.NET ont l'habitude de mettre des données en cache pour éviter de requêter a chaque fois la base de données. Et il est toujours utilie de penser que vos utilisateurs mobiles n'ont pas troujours une super connexion 3G/WIFI et un for...
Cliquez pour lire la suite de l'article par Nicolas [TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION[TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION par cyril
Lorsque l'on créé un Work Item dans TFS, il est possible de le classer dans un "area" et dans une "iteration". Dans la plupart des types de projet, un "area" correspond à une catégorie, une "iteration" à un numéro de version. Il est possible de cré...
Cliquez pour lire la suite de l'article par cyril SQL : FONCTIONS D'AGRéGATION MIN/MAX ET VALEURS NULLSQL : FONCTIONS D'AGRéGATION MIN/MAX ET VALEURS NULL par coq
Les fonctions d'agrégation comme MIN et MAX ignorent les valeurs NULL présentes dans le jeu de données sur lequel porte leur calcul, d'où le fameux message d'avertissement : Warning: Null value is eliminated by an aggregate or other SET operation...
Cliquez pour lire la suite de l'article par coq
Logiciels
Bureau de Gestion - ERP Devis Facturation (2.02)BUREAU DE GESTION - ERP DEVIS FACTURATION (2.02)
- Version gratuite du 10/06/2010
Le Bureau de Gestion est un logiciel dédié à la gestion de l'en...
Cliquez pour télécharger Bureau de Gestion - ERP Devis Facturation sDEVIS-FACTURES vlPRO (3.8.0)SDEVIS-FACTURES VLPRO (3.8.0)sDEVIS-FACTURES vlPRO a été mis au point pour permettre besoins des particuliers, créateurs, entr... Cliquez pour télécharger sDEVIS-FACTURES vlPRO LettresFaciles (5.6.0)LETTRESFACILES (5.6.0)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles MyPlanning 2010 (5.6.0)MYPLANNING 2010 (5.6.0)MyPlanning 2010 permet de créer des plannings sous la représentation de diagrammes. Plannings pré... Cliquez pour télécharger MyPlanning 2010 Emicsoft Mac DVD en iPad Convertisseur (3.1.16)EMICSOFT MAC DVD EN IPAD CONVERTISSEUR (3.1.16)Emicsoft Mac DVD en iPad Convertisseur, logiciel professionnel de convertir les fichiers DVD en i... Cliquez pour télécharger Emicsoft Mac DVD en iPad Convertisseur
|