Link to home
Start Free TrialLog in
Avatar of TeChNiCh
TeChNiCh

asked on

Memo1 Specify

i asked this question b4 but i want it more specified this time :)

i want to specify a memo1 format so on buttonclick then Add(Edit1.text, Edit2.text,edit3.text,edit4.text)
and when its done i want memo1 to look like Columns this but with out the |'s:

Description     | Amount  |Price  |Total Price |
------------------------------------------------------
   Edit1.text      | Edit2.t | Edit3 | Edit4.text |

The lines is just the "column" where each edit should be..
its seems hard... hope someone can help
Avatar of edey
edey

I would think you'd be stuck doing this with tabs.  For an interesting discussion about doing just this, with a TRichEdit, you can read this discussion:  http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=9a38be920dd072f8&seekd=921284744#921284744

GL
Mike
The first thing, you should do, is to set Fixed-Pitch font, like System or FixedSys to the memo, then just count length of each cell in characters.
Think, that is what you're looking for:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Add: TButton;
    procedure AddClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const MaxCols=15;
      MaxDescription=25;

var
  Form1: TForm1;
  TempelateText: string;
  TempelateNum: string;

implementation

{$R *.DFM}

procedure TForm1.AddClick(Sender: TObject);
begin
  Memo1.Lines.Add(Format(TempelateNum,[Edit1.Text, StrToInt(Edit2.Text), StrToCurr(Edit3.Text), StrToCurr(Edit4.Text)]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Font.Name:='Courier';
  Memo1.Font.Pitch:=fpFixed;
  TempelateText:= '%-' + IntToStr(MaxDescription)+'s | %'+IntToStr(MaxCols)+'s | %'+IntToStr(MaxCols)+'s | %'+IntToStr(MaxCols)+'s';
  TempelateNum:= '%-' + IntToStr(MaxDescription)+'s | %'+IntToStr(MaxCols)+'d | %'+IntToStr(MaxCols)+'m | %'+IntToStr(MaxCols)+'m';
  Memo1.Lines.Add(Format(TempelateText,['Description', 'Amount', 'Price', 'Total Price']));
  Memo1.Lines.Add(StringOfChar('-',Length(Memo1.Lines[0])));
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial