We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Help to cut and fomat a memo1

boycoder
boycoder asked
on
Medium Priority
746 Views
Last Modified: 2012-05-11
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
Comment
Watch Question

Author

Commented:
Forgot to say "the buyer hasnt left a note"  .. anything on this line , add to the edit box as it will always change.

Commented:

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 ...

Author

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.

Commented:
what about using a ValueListEditor or a ListBox

Author

Commented:
as long as the listbox shall work with the format, sounds good.

Commented:
wait 5 min, make a simple demo with Tmemo

Commented:
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;

Commented:
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.

Author

Commented:
Thanks but before i test this, could you make it so that this is all done MEMO ON CHANGE, with no buttons.

Commented:
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 
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:

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

Author

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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.