• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

Help to cut and fomat a memo1

Hi

Need some help guys.

I have the following format of text that never changes..

The fomat is an address. Obviously the address will shange but the format doesnt.
when i paste this into a memo, on change i want it to auto add them to edit boxes.
This is the address format

Buyer (<<cut this out)
Amanda Crater (<< cut this out)
colman25 (<< add this line to DBname.text)
manfff5@btinternet.com      Note to seller (<< add this LINE to DBadd1)* CUT OUT "NOTE TO SELLER" *
The buyer hasn't sent a note. ( << add this LINE to DBnote.text)
Shipping address - confirmed (< add this tLINE o DBstatus.text)
Amanda Crafer ( << add this LINE to DBadd2.text)
25 Kebg Drive ( << add this LINE to DB1.text)
Brandon, Suffolk  ( << add this LINE to DB2.text)
IO9HHUA ( << add line this to DB3.text)
United Kingdom ( cut this out)

I need them put into edit boxes, i will add the edit boxes at the end of the address format in brackets.

important!

when i say CUT OUT NOTE TO SELLER.. i mean add some codeto say if "note so seller" exists, cut it out, because i dont know how long email address will be and i dont want it to cut out long emails.
thanks
0
boycoder
Asked:
boycoder
  • 6
  • 5
  • 2
1 Solution
 
boycoderAuthor Commented:
Forgot to say "the buyer hasnt left a note"  .. anything on this line , add to the edit box as it will always change.
0
 
BdLmCommented:

is it a must items to have all in a memo ?  you need to work with pos(...) function to locate that sting in the memo ...
0
 
boycoderAuthor Commented:
well, the code i grab is the format of the address, as long as i can paste it into a component, any easy way to get the format into edit boxes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BdLmCommented:
what about using a ValueListEditor or a ListBox
0
 
boycoderAuthor Commented:
as long as the listbox shall work with the format, sounds good.
0
 
BdLmCommented:
wait 5 min, make a simple demo with Tmemo
0
 
Mahdi78Commented:
Try this code

procedure TForm1.Button1Click(Sender: TObject);
var S: string;
begin
DBname.Text := Memo1.Lines.Strings[2];
S :=  Memo1.Lines.Strings[3];  S:= Trim(S);
Delete(S, Length(S)- 13, 14);  S:= Trim(S);
DBadd1.Text := S;
DBnote.Text := Memo1.Lines.Strings[4];
DBstatus.Text := Memo1.Lines.Strings[5];
DBadd2.Text := Memo1.Lines.Strings[6];
DB1.Text := Memo1.Lines.Strings[7];
DB2.Text := Memo1.Lines.Strings[8];
DB3.Text := Memo1.Lines.Strings[9];
end;
0
 
BdLmCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit, StrUtils;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


///  add dummy text to the memo
procedure TForm1.Button1Click(Sender: TObject);

begin
     memo1.lines.add ( ' Buyer (<<cut this out) ');
     memo1.lines.add ( 'Amanda Crater (<< cut this out)');
     memo1.lines.add ( ' Buyer xxxxx (<<cut this out) ');
     memo1.lines.add ( ' Buyer ttttt (<<cut this out) ');
end;

///  copy memo as string
procedure TForm1.Button2Click(Sender: TObject);
var   aStr  : String;
begin
       aStr := memo1.Text;

       Edit1.Text :=  aStr;

end;

///  demo Pos EX
///
///     function PosEx(Str, Source : string, StartFrom : cardinal = 1): integer;
///     function RightStr(const AString: AnsiString; const Count: Integer): AnsiString;
///     function Copy(S; Index, Count: Integer): string
procedure TForm1.Button3Click(Sender: TObject);
var   aStr  : String;
      i     : Integer;
begin
      aStr := memo1.Text;

      i := PosEx ('Amanda' , aStr, 1);

      astr := Copy(astr,i, 5);      ///  take 5 Chars
                                                      ...
      Edit2.Text := aStr;


end;

end.
0
 
boycoderAuthor Commented:
Thanks but before i test this, could you make it so that this is all done MEMO ON CHANGE, with no buttons.
0
 
BdLmCommented:
strutils offers a wide range of function extraction from a string a ceratin substring

function PosEx(Str, Source : string, StartFrom : cardinal = 1): integer;    
function RightStr(const AString: AnsiString; const Count: Integer): AnsiString;
function Copy(S; Index, Count: Integer): string
    ....


see that link for all details http://delphi.about.com/od/beginners/l/blrtlstringhand.htm 
0
 
Mahdi78Commented:
Put the code in Onchange memo1 event like this

procedure TForm1.Memo1Change(Sender: TObject);
var S: string;
begin
DBname.Text := Memo1.Lines.Strings[2];
S :=  Memo1.Lines.Strings[3];  S:= Trim(S);
Delete(S, Length(S)- 13, 14);  S:= Trim(S);
DBadd1.Text := S;
DBnote.Text := Memo1.Lines.Strings[4];
DBstatus.Text := Memo1.Lines.Strings[5];
DBadd2.Text := Memo1.Lines.Strings[6];
DB1.Text := Memo1.Lines.Strings[7];
DB2.Text := Memo1.Lines.Strings[8];
DB3.Text := Memo1.Lines.Strings[9];
end;
0
 
BdLmCommented:

if you work with a memo and the user add addition text to the memo you need to analyse all the string, loop through the content of the memo line by line as MAHDI79 solution
or taker all strings and read the content with string processing functions ,
a fixed format will be much more stable ....  take ListBox or ....
///   onCHange  Event
procedure TForm1.Memo1Change(Sender: TObject);

var   aStr  : String;
      i     : Integer;
begin
      aStr := memo1.Text;

      i := PosEx ('Amanda' , aStr, 1);

      astr := Copy(astr,i, 5);      ///  take 5 Chars

      Edit2.Text := aStr;
end;

Open in new window

0
 
boycoderAuthor Commented:
Excellent. Also thanks to the other guy, he did alot of work and i am unsure how to split points if possible. i will be asking alot more 500pts Questions, hopefully i can give some points .. cheers lads
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now