home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2002 September / PCPlus_193_Laplink2000.iso / Prog / delphi / formatstr / fmt.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-04-30  |  1.1 KB  |  54 lines

  1. unit fmt;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     inted: TEdit;
  12.     outputed: TEdit;
  13.     ComboBox1: TComboBox;
  14.     floated: TEdit;
  15.     ComboBox2: TComboBox;
  16.     procedure ComboBox1Change(Sender: TObject);
  17.     procedure ComboBox2Change(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. const
  25.    DEFAULTSTR = 'Result is: [ % ]';
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.dfm}
  32.  
  33. procedure TForm1.ComboBox1Change(Sender: TObject);
  34. var
  35.    s : string;
  36. begin
  37.    s := DEFAULTSTR;
  38.    Insert( ComboBox1.Text, s, Pos('%', DEFAULTSTR )+1);
  39.    Caption := 'Format string = "'+s+'"';
  40.    outputed.Text := Format(s,[StrToInt(inted.Text)]);
  41. end;
  42.  
  43. procedure TForm1.ComboBox2Change(Sender: TObject);
  44. var
  45.    s : string;
  46. begin
  47.    s := DEFAULTSTR;
  48.    Insert( ComboBox2.Text, s, Pos('%', DEFAULTSTR )+1);
  49.    Caption := 'Format string = "'+s+'"';
  50.    outputed.Text := Format(s,[StrToFloat(floated.Text)]);
  51. end;
  52.  
  53. end.
  54.