mdmomo
Messages postés8Date d'inscriptionvendredi 5 décembre 2003StatutMembreDernière intervention25 septembre 2006
-
1 déc. 2004 à 13:13
JulioDelphi
Messages postés2226Date d'inscriptiondimanche 5 octobre 2003StatutMembreDernière intervention18 novembre 2010
-
1 déc. 2004 à 21:51
Bonjour a tous.
Je souhaiterais formater un nombre de type Double
A l'aide d'un événement ComboBox
J'ai rempli mon Combo avec des fonctions Format
je sais bien quelle est de type String dans mon Combo...
Donc je ne peut pas exécuter ma fonction ????? directement
Est ce qu'il y a quelqu'un qui peut m?aider son passer chaque fois a réécrire La bonne fonction et le numéro index de ma ComboBox ?
C'est a dire que mon Label ou mon Edit reçoit directement la commande de ma Combo.
for i:=0 to ListeFormat.Count-1 do
ComboBox1.Items.Add(ListeFormat[i]); //remplir le combobox
ComboBox1.ItemIndex:=0; //Affiche le premier index dans le combobox
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Label1.caption := ComboBox1.Items[ComboBox1.ItemIndex];
mdmomo
Messages postés8Date d'inscriptionvendredi 5 décembre 2003StatutMembreDernière intervention25 septembre 2006 1 déc. 2004 à 16:05
J'affiche plusieurs styles de format dans un ComboBox.
Chaque fois que je sélectionne un format dans la liste ( ComboBox)
le nombre dans le Edit ou bien du Label Change de format.
J'aimerais bien savoir comment s'il y a une autre méthode sans passer ni par un IF.. else ou bien Case.
Ou bien comment je peux passer ma fonction ' (FormatFloat ('',##.##'', Nbr )) '
Sans les guillemets (FormatFloat ( ',##.##', Nbr )) à Edit1.text ou bien à Label1.caption
Merci !
unit UFormatFloat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ComboBox1: TComboBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Const Nbr = 1200034.567;
procedure TForm1.FormCreate(Sender: TObject);
var
ListeFormat : TStringList;
result : Double;
i : Integer;
begin
Edit1.Text := floatToStr(Nbr);
Label1.caption := floatToStr(Nbr);
ListeFormat :=TStringList.Create;
ListeFormat.Add('FormatFloat ('',##.##'', Nbr )');
ListeFormat.Add('FormatFloat ( ''00000'', Nbr )');
ComboBox1.Items.Assign(ListeFormat);
ComboBox1.ItemIndex:=0; //Affiche le premier index dans le combobox
ListeFormat.free;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Label1.caption := ComboBox1.Items[ComboBox1.ItemIndex];
Edit1.Text := (FormatFloat (',##.##', Nbr ));
end;
end.
Vous n’avez pas trouvé la réponse que vous recherchez ?