[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

format cut memo1

Hi, this is the format

Item Number 130514181666      £31.77 GBP      1      £31.79 GBP

my code:

DBitemText := Memo1.Lines.Strings[22];

I need to cut out evetything in that line, so i just see the number.
I dont want to see any price or "item number"  in that box.
0
boycoder
Asked:
boycoder
  • 19
  • 7
  • 7
  • +2
1 Solution
 
boycoderAuthor Commented:
the format always starts with the word item number, so maybe cut that word.. and anything after a space at the end of the number cut.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Try this
procedure TForm1.Button1Click(Sender: TObject);
  Function GetNumber(Value: String): String;
  var
    s, s1: String;
    list: TStrings;
  begin
    s := Trim(Value);
    repeat
      s1 := s;
      s := StringReplace(s, '  ', ' ', [rfReplaceAll]);
    until s = s1;
    list := TStringList.create;
    try
      list.Delimiter := ' ';
      list.DelimitedText := s;
      result := list[5];
    finally
      list.Free;
    end;
  end;

begin
ShowMessage(GetNumber('Item Number 130514181666      £31.77 GBP      1      £31.79 GBP'));
end;

Open in new window

0
 
boycoderAuthor Commented:
SORRY FOGOT TO ADD, it is part of my on change event.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
boycoderAuthor Commented:
and the number always changes
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
A more explanation and a bit more code could point us to help you better.

Have you tried the function? It gets anyway the number in that position even if it changes
0
 
boycoderAuthor Commented:
i havnt as i dont want to mess the code up, i need to work it inside my memo change. can you rpovide the code for that, as simple as possible as i have stacks of code inside the memochange and its getting confusing. cheers
0
 
Marco GasiFreelancerCommented:
You could use TPerlRegEx unit (http://www.regexguru.com/2008/08/tperlregex-for-delphi-2009/). This unit enable you to use regular expression in delphi (look for info at http://www.regular-expressions.info/delphi.html)

Using this unit you could write this
 
procedure doSomething();
var
  rx: TPerlRegEx;
begin
  rx := TPerlRegEx.Create;
  try
    rx.RegEx := '(?<=item number\s)\d*(?=\s)';
    rx.Subject := Memo1.Lines.Strings[22];
    rx.Options := [preCaseLess];
    if rx.Match then
      DBitemText := rx.MatchedText;
  finally
    rx.Free;
  end;
end;

Open in new window


Cheers
0
 
Marco GasiFreelancerCommented:
Sorry: the first link I provided is for component the second one is for bot class and component as you prefer. I suggest to refer to the second link posted above: http://www.regular-expressions.info/delphi.html.

Bye
0
 
boycoderAuthor Commented:
Thanks but i really only need the most simple code to add to my current code in my memo change.

Just to cut out the word "item number" and cut eveything else after the "space" after the number itself.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
@boycoder
You are not saying where do you need the number value and wich type it must be.

The only thing that I know from you for now is that you are filling a field with a Item value of the memo

No explanation of how this item is populated
No explanation about the use of the retrieved number
No explanation about the change of the memo, as I assume that if you need to put the code in OnChange event it means that the Memo text could change in any time

Without any other input became very hard to try to help you

By the way in a little example

procedure TForm1.Memo1Change(Sender: TObject);
var
  MyNumber: String;
  Function GetNumber(Value: String): String;
  var
    s, s1: String;
    list: TStrings;
  begin
    s := Trim(Value);
    repeat
      s1 := s;
      s := StringReplace(s, '  ', ' ', [rfReplaceAll]);
    until s = s1;
    list := TStringList.create;
    try
      list.Delimiter := ' ';
      list.DelimitedText := s;
      result := list[5];
    finally
      list.Free;
    end;
  end;

begin
  MyNumber := GetNumber(Memo1.Lines[22]);
end;

0
 
Ephraim WangoyaCommented:
Try this
function GetItemNumber(const S: string): string;
const
  CItemNo = 'Item Number';
  CNumericSet: TSysCharSet = ['0','1','2','3','4','5','6','7','8','9'];
var
  Index: Integer;
begin
  Result := Trim(Copy(Trim(S), Length(CItemNo) + 1, 255));
  Index := 1;
  while Result[Index] in CNumericSet do
    Inc(Index);
  SetLength(Result, Index);
end;

Open in new window

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
But what do you really need? The item number or the number between prices?

In case of the item number change the function as follows

Function GetNumber(Value: String): String;
  var
    s, s1: String;
    list: TStrings;
  begin
    s := Trim(Value);
    repeat
      s1 := s;
      s := StringReplace(s, '  ', ' ', [rfReplaceAll]);
    until s = s1;
    list := TStringList.create;
    try
      list.Delimiter := ' ';
      list.DelimitedText := s;
      result := list[2];
    finally
      list.Free;
    end;
  end;
0
 
boycoderAuthor Commented:
ive tried both functions but still all the text remains inside the DBitem.text
0
 
boycoderAuthor Commented:
when i paste
Item Number 130514181666      £31.77 GBP      1      £31.79 GBP

into a memo1..

i want my DBitem.text to say  "130514181666 "


my code inside the onchange memo event.
DBitemText := Memo1.Lines.Strings[22];
0
 
Ephraim WangoyaCommented:
Is this part of your last question
function GetItemNumber(const S: string): string;
const
  CItemNo = 'Item Number';
  CNumericSet: TSysCharSet = ['0','1','2','3','4','5','6','7','8','9'];
var
  Index: Integer;
begin
  Result := Trim(Copy(Trim(S), Length(CItemNo) + 1, 255));
  Index := 1;
  while Result[Index] in CNumericSet do
    Inc(Index);
  SetLength(Result, Index);
end;

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];

  DBitemText := GetItemNumber(Memo1.Lines.Strings[22]);
end;

Open in new window

0
 
boycoderAuthor Commented:
yes exactly mate
0
 
Ephraim WangoyaCommented:

And its actually
   DBitem.Text := GetItemNumber(Memo1.Lines[22]);
0
 
Ephraim WangoyaCommented:

You should also check if Line 22 exists just to be safe eg

  if Memo1.Lines.Count > 22 then
     DBitem.Text := GetItemNumber(Memo1.Lines[22]);
0
 
boycoderAuthor Commented:
yea i have else begin " " already added in the other part of the code to show an error if its doesnt exist, but it always will as its always the same format.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
So my final code is this.



procedure TForm1.Memo1Change(Sender: TObject);

  Function GetNumber(Value: String): String;
  var
    s, s1: String;
    list: TStrings;
  begin
    s := Trim(Value);
    repeat
      s1 := s;
      s := StringReplace(s, '  ', ' ', [rfReplaceAll]);
    until s = s1;
    list := TStringList.create;
    try
      list.Delimiter := ' ';
      list.DelimitedText := s;
      result := list[2];
    finally
      list.Free;
    end;
  end;

begin
  try
    DBitemText :=  GetNumber(Memo1.Lines[22]);
  except
    DBitemText := '';
  end;
end;

0
 
boycoderAuthor Commented:
that works mate, but it gives a final result in the edit box as "t"  
0
 
boycoderAuthor Commented:
by the way its not memoline [22] but 17..
its ok tho ill just edit it accordly however still shows "t"
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
@ewangoya, just for curiosity, where did you take that part of his code?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
I see, from his last question paqed. Just a link to there could save lot of time to understand :)
0
 
Ephraim WangoyaCommented:

I just happened to be browsing accepted solutions and came across it
0
 
boycoderAuthor Commented:
still cant get it working, it would be ideal to use it withough a function a simple as possible if you can to fit in with my code.
0
 
jimyXCommented:
As I understood you want to extract that number whenever the memo has changed. If yes, then here you are:
procedure TForm1.Memo1Change(Sender: TObject);
var
  i:integer;
begin
  for i:= 0 to Memo1.Lines.Count-1 do
    begin
      if (pos('Item Number',memo1.Lines[i]) > 0) and (pos('£',memo1.Lines[i]) > 0) and (pos('GBP',memo1.Lines[i]) > 0) then  // you may add case sensitivity check
        begin
          Edit1.Text := copy(memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12,posex(' ',memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12)-pos('Item Number',memo1.Lines[i])-12);
        end;
    end;
end;

Open in new window

Do you have many lines that has the same format as this one?
0
 
boycoderAuthor Commented:
no mate just the code u seen before,also i get

posex is undeclared?
0
 
boycoderAuthor Commented:
here is my full code



procedure TForm13.Memo1Change(Sender: TObject);

var S: string;

  str : string;
  i, a : integer;
     Clipboard: TClipboard;
begin
DB4.TEXT:=(DateTimeToStr(Now)) ;

     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];
DBhhb.Text := Memo1.Lines.Strings[16];
DBitem.Text := Memo1.Lines.Strings[17];
DBPRICE.Text := Memo1.Lines.Strings[22];
 begin
  for i:= 0 to Memo1.Lines.Count-1 do
    begin
      if (pos('Item Number',memo1.Lines[i]) > 0) and (pos('£',memo1.Lines[i]) > 0) and (pos('GBP',memo1.Lines[i]) > 0) then  // you may add case sensitivity check
        begin
          DBitem.Text := copy(memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12,posex(' ',memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12)-pos('Item Number',memo1.Lines[i])-12);
        end;


end;

Open in new window

0
 
jimyXCommented:
Sorry forget to tell you:
uses StrUtils;
0
 
boycoderAuthor Commented:
added, but still undeclared.. thats odd as i thought that would fix it.
0
 
jimyXCommented:
Ya that's really odd. Can you show the entire unit please?
0
 
boycoderAuthor Commented:
this is from top, to the code, not the whole unit as its is super super long
unit Unit13;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, clipbrd, DBCtrls, TFlatButtonUnit,
  TFlatCheckBoxUnit, TFlatComboBoxUnit, TFlatEditUnit, TFlatMemoUnit,
  ExtCtrls, DB, ADODB, Grids, DBGrids, jpeg, Menus,
  TFlatPanelUnit, shellapi, wininet, DateUtils, Buttons, StrUtils;



type
TReportTime = (rtToday, rtThisWeek, rtThisMonth);


  TForm13 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    fullname: TLabel;
    name: TLabel;
    email: TLabel;
    area: TLabel;
    city: TLabel;
    postcode: TLabel;
    timedate: TLabel;
    Refresh: TFlatButton;
    DB5: TFlatComboBox;
    Label5: TLabel;
    Edit1: TFlatEdit;
    folder: TFlatEdit;
    DBsheet: TFlatEdit;
    DBname: TFlatEdit;
    DBadd1: TFlatEdit;
    DBadd2: TFlatEdit;
    DB1: TFlatEdit;
    DB2: TFlatEdit;
    DB3: TFlatEdit;
    DB4: TFlatEdit;
    Memo1: TFlatMemo;
    FlatButton4: TFlatButton;
    FlatButton5: TFlatButton;
    Image2: TImage;
    scan: TFlatButton;
    Closeit: TFlatButton;
    FlatMemo1: TFlatMemo;
    FlatMemo2: TFlatMemo;
    send: TFlatButton;
    ComboBox1: TFlatComboBox;
    ComboBox2: TFlatComboBox;
    B2: TFlatButton;
    padd1: TFlatButton;
    padd2: TFlatButton;
    item: TFlatEdit;
    item2: TFlatEdit;
    D1: TFlatButton;
    D2: TFlatButton;
    Labelb: TLabel;
    labela: TLabel;
    flatpanel2: TFlatPanel;
    flatpanel1: TFlatPanel;
    FlatPanel3: TFlatPanel;
    acc2: TImage;
    acc1: TImage;
    labelitembb: TLabel;
    labelitemfirst: TLabel;
    Label4: TLabel;
    labelsales: TLabel;
    sales: TFlatComboBox;
    Label6566: TLabel;
    Label6: TLabel;
    postban: TFlatButton;
    streetban: TFlatButton;
    fullnameban: TFlatButton;
    FlatPanel4: TFlatPanel;
    newlabelname: TLabel;
    acc3: TImage;
    newlabel1: TLabel;
    newbutton1: TFlatButton;
    deld: TFlatButton;
    newedit1: TFlatEdit;
    addit: TFlatButton;
    FlatPanel5: TFlatPanel;
    FlatPanel6: TFlatPanel;
    Label7: TLabel;
    acc4: TImage;
    Label8: TLabel;
    panel6b: TFlatButton;
    del6: TFlatButton;
    thd: TFlatEdit;
    add6: TFlatButton;
    gghhh: TFlatButton;
    fggr: TFlatButton;
    bfgdf: TFlatButton;
    dwed432r: TFlatButton;
    FlatPanel800: TFlatPanel;
    label800: TLabel;
    acc5: TImage;
    send800: TFlatButton;
    del800: TFlatButton;
    text800: TFlatEdit;
    add800: TFlatButton;
    sendpin800: TFlatButton;
    lab800: TLabel;
    Label13: TLabel;
    FlatPanel7: TFlatPanel;
    Label14: TLabel;
    FlatPanel8: TFlatPanel;
    Label16: TLabel;
    label2100: TLabel;
    del2100: TFlatButton;
    edit2100: TFlatEdit;
    add2100: TFlatButton;
    telephone: TFlatEdit;
    Label18: TLabel;
    phoneban: TFlatButton;
    xxbm: TFlatPanel;
    labs: TLabel;
    label99: TLabel;
    acc7: TImage;
    getitgo: TFlatButton;
    g5ttr: TFlatButton;
    edit99: TFlatEdit;
    vvvvfd: TFlatButton;
    getitgopin: TFlatButton;
    xboxliveuk: TFlatPanel;
    Label19: TLabel;
    xbluk: TFlatPanel;
    Label20f: TLabel;
    label001: TLabel;
    acc8: TImage;
    sendbn: TFlatButton;
    lololk: TFlatButton;
    xbed: TFlatEdit;
    vvbbhj: TFlatButton;
    lime: TFlatButton;
    MainMenu2: TMainMenu;
    AccountOptions1: TMenuItem;
    ViewFeedback1: TMenuItem;
    EmailUser1: TMenuItem;
    ViewBanList1: TMenuItem;
    ViewPINVoiceMessage1: TMenuItem;
    Label20: TLabel;
    account3: TFlatEdit;
    pin: TFlatEdit;
    Label21: TLabel;
    EDITS: TFlatButton;
    Image3: TImage;
    Image1: TImage;
    Image4: TImage;
    Image5: TImage;
    hhgg: TImage;
    jyyyyggf: TImage;
    yyees: TImage;
    bbbc: TImage;
    Image8: TImage;
    Label23: TLabel;
    FlatPanel11: TFlatPanel;
    Label28: TLabel;
    Label29: TLabel;
    FlatPanel12: TFlatPanel;
    Label10: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Image9: TImage;
    FlatPanel13: TFlatPanel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    FlatPanel14: TFlatPanel;
    Label38: TLabel;
    Image10: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    FlatPanel15: TFlatPanel;
    Label9: TLabel;
    Label15: TLabel;
    Label39: TLabel;
    Label41: TLabel;
    FlatPanel16: TFlatPanel;
    Label43: TLabel;
    Image15: TImage;
    FlatPanel17: TFlatPanel;
    Image16: TImage;
    Label44: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    FlatPanel18: TFlatPanel;
    Label49: TLabel;
    Image17: TImage;
    Image18: TImage;
    Label11: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    Label52: TLabel;
    FlatPanel19: TFlatPanel;
    Label53: TLabel;
    Label54: TLabel;
    Image19: TImage;
    FlatPanel20: TFlatPanel;
    FlatPanel21: TFlatPanel;
    Label22: TLabel;
    Label55: TLabel;
    Label56: TLabel;
    Label57: TLabel;
    FlatPanel22: TFlatPanel;
    Label58: TLabel;
    Label59: TLabel;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    FlatPanel23: TFlatPanel;
    Label12: TLabel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    FlatPanel24: TFlatPanel;
    Label63: TLabel;
    Label42: TLabel;
    Label64: TLabel;
    Image23: TImage;
    labelusername: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    ADOQuery1: TADOQuery;
    points: TFlatButton;
    Label67: TLabel;
    DBstatus: TFlatEdit;
    Label68: TLabel;
    DBnote: TFlatEdit;
    Label70: TLabel;
    DBhhb: TFlatEdit;
    Label71: TLabel;
    DBitem: TFlatEdit;
    Label72: TLabel;
    DBPRICE: TFlatEdit;
    Label73: TLabel;
    Image6: TImage;
    SaleOptions1: TMenuItem;
    Overridesaleprotection1: TMenuItem;
    Image7: TImage;
    image2100: TImage;


    procedure FormActivate(Sender: TObject);

    procedure Memo1Change(Sender: TObject);
    procedure b1Click(Sender: TObject);
    procedure RefreshClick(Sender: TObject);


    
    procedure FlatButton3Click(Sender: TObject);
    procedure FlatButton4Click(Sender: TObject);
    procedure FlatButton5Click(Sender: TObject);
   
    procedure FormCreate(Sender: TObject);
    procedure scanClick(Sender: TObject);
    procedure CloseitClick(Sender: TObject);
    procedure FlatButton6Click(Sender: TObject);
    procedure viewbanClick(Sender: TObject);
    procedure delClick(Sender: TObject);
    procedure CheckClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DB3Change(Sender: TObject);
    procedure feedbackClick(Sender: TObject);
    procedure emailuserClick(Sender: TObject);
    procedure acc1Click(Sender: TObject);
    procedure ComboBox1CloseUp(Sender: TObject);

    procedure Button2Click(Sender: TObject);
    procedure xxClick(Sender: TObject);
    procedure sendClick(Sender: TObject);


    procedure B2Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
    procedure padd1Click(Sender: TObject);
    procedure padd2Click(Sender: TObject);


    procedure D1Click(Sender: TObject);
    procedure D2Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBnameChange(Sender: TObject);
    procedure postbanClick(Sender: TObject);
    procedure streetbanClick(Sender: TObject);
    procedure fullnamebanClick(Sender: TObject);
    procedure newbutton1Click(Sender: TObject);
    procedure ddedClick(Sender: TObject);
    procedure additClick(Sender: TObject);
    procedure deldClick(Sender: TObject);
    procedure FlatButton1Click(Sender: TObject);
    procedure FlatButton2Click(Sender: TObject);
    procedure del6Click(Sender: TObject);
    procedure add6Click(Sender: TObject);
    procedure panel6bClick(Sender: TObject);
    procedure pinnumberClick(Sender: TObject);
    procedure gghhhClick(Sender: TObject);
    procedure fggrClick(Sender: TObject);
    
    procedure dwed432rClick(Sender: TObject);
    procedure eightClick(Sender: TObject);
    procedure add800Click(Sender: TObject);
    procedure del800Click(Sender: TObject);
    procedure send800Click(Sender: TObject);
    procedure sendpin800Click(Sender: TObject);
    procedure xbl2100Click(Sender: TObject);
    procedure bbbClick(Sender: TObject);
    procedure kllmClick(Sender: TObject);
    procedure del2100Click(Sender: TObject);
    procedure add2100Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure bhggClick(Sender: TObject);
    procedure phonebanClick(Sender: TObject);
    procedure fdjfjgClick(Sender: TObject);
    procedure getitgoClick(Sender: TObject);
    procedure getitgopinClick(Sender: TObject);
    procedure vvvvfdClick(Sender: TObject);
    procedure g5ttrClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure aqqqClick(Sender: TObject);
    procedure ffttyClick(Sender: TObject);
    procedure vvbbhjClick(Sender: TObject);
    procedure lololkClick(Sender: TObject);
    procedure sendbnClick(Sender: TObject);
   
    procedure limeClick(Sender: TObject);
    procedure ViewFeedback1Click(Sender: TObject);
    procedure EmailUser1Click(Sender: TObject);
    procedure ViewBanList1Click(Sender: TObject);
    procedure EDITSClick(Sender: TObject);
    procedure dggClick(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure Image4Click(Sender: TObject);
    procedure Image5Click(Sender: TObject);
    procedure hhggClick(Sender: TObject);
    procedure jyyyyggfClick(Sender: TObject);
    procedure yyeesClick(Sender: TObject);
    procedure bbbcClick(Sender: TObject);
    procedure bfgdfClick(Sender: TObject);
    procedure ggfbdClick(Sender: TObject);
    procedure pointsClick(Sender: TObject);
    procedure DBitemChange(Sender: TObject);
    procedure Overridesaleprotection1Click(Sender: TObject);
    procedure Image7Click(Sender: TObject);


    procedure image2100Click(Sender: TObject);

   








  private
  procedure GetDateFor(AReportTime: TReportTime; var AStartDate, AEndDate: TDateTime);



    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form13: TForm13;

implementation

uses Unit1, Unit15, Unit2, Unit18, Unit19, Unit21, Unit22, Unit23, UNIT24, unit25,
  Unit26, unit27;

{$R *.dfm}
  
function IsBadWord(AList: array of string; const AText: string): Boolean;
  var
    J, Len: Integer;
  begin
    Len := Length(AList);
    for J := 0 to Len -1 do
    begin
      Result := Pos(UpperCase(Trim(AList[J])), Uppercase(AText)) > 0;
      if Result then
        Exit;
    end;
    Result := False;
    END;
procedure TForm13.FormActivate(Sender: TObject);
begin
memo1.lines.clear;
edit1.readonly:=(true);

edit1.Text:= form1.adotable2.Fields[2].AsString;
folder.Text:= form1.adotable2.Fields[3].AsString;
DBSheet.Text:= form1.adotable2.Fields[4].AsString;
DBname.Text:= form1.adotable2.Fields[5].AsString;
DBadd1.Text:= form1.adotable2.Fields[6].AsString;
DBadd2.Text:= form1.adotable2.Fields[7].AsString;
DB1.Text:= form1.adotable2.Fields[8].AsString;
DB2.Text:= form1.adotable2.Fields[9].AsString;
DB3.Text:= form1.adotable2.Fields[10].AsString;
DB4.Text:= form1.adotable2.Fields[11].AsString;
DB5.Text:= form1.adotable2.Fields[1].AsString;
flatmemo2.text:= form1.adotable2.Fields[12].AsString;
labelsales.caption:= form1.adotable2.Fields[13].AsString;
sales.text:= form1.adotable2.Fields[13].AsString;
telephone.text:= form1.adotable2.Fields[14].AsString;
account3.text:= form1.adotable2.Fields[15].AsString;
pin.text:= form1.adotable2.Fields[16].AsString;





edit1.SetFocus;
Edit1.SelectAll;
















end;

procedure TForm13.Memo1Change(Sender: TObject);

var S: string;

  str : string;
  i, a : integer;


     Clipboard: TClipboard;
begin
DB4.TEXT:=(DateTimeToStr(Now)) ;

     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];
DBhhb.Text := Memo1.Lines.Strings[16];
DBitem.Text := Memo1.Lines.Strings[17];
DBPRICE.Text := Memo1.Lines.Strings[22];
                          begin

  for i:= 0 to Memo1.Lines.Count-1 do
    begin
      if (pos('Item Number',memo1.Lines[i]) > 0) and (pos('£',memo1.Lines[i]) > 0) and (pos('GBP',memo1.Lines[i]) > 0) then  // you may add case sensitivity check
        begin
          DBitem.Text := copy(memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12,posex(' ',memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12)-pos('Item Number',memo1.Lines[i])-12);
        end;


end;

 end;

Open in new window

0
 
Ephraim WangoyaCommented:

Are you sure the line you are looking for is on line 17

Can you check


procedure TForm1.Memo1Change(Sender: TObject);
var 
  S: string;
begin
  ShowMessage(Memo1.Lines.Strings[17]);
end;

Open in new window

0
 
boycoderAuthor Commented:
yes because i test my program and its fine, but when i want to extract only the number,it doesnt work.
0
 
boycoderAuthor Commented:
if you look at my source, ull see i still have my original code in that looks at line 17, and works. But when i test the new thing im trying to do, it doesnt work.
0
 
jimyXCommented:
OK, I replaced the PosEx with Pos:
procedure TForm13.Memo1Change(Sender: TObject);

var S: string;

  str : string;
  i, a : integer;
     Clipboard: TClipboard;
begin
DB4.TEXT:=(DateTimeToStr(Now)) ;

     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];
DBhhb.Text := Memo1.Lines.Strings[16];
DBitem.Text := Memo1.Lines.Strings[17];
DBPRICE.Text := Memo1.Lines.Strings[22];
 begin
  for i:= 0 to Memo1.Lines.Count-1 do
    begin
      if (pos('Item Number',memo1.Lines[i]) > 0) and (pos('£',memo1.Lines[i]) > 0) and (pos('GBP',memo1.Lines[i]) > 0) then  // you may add case sensitivity check
        begin
          DBitem.Text := copy(memo1.Lines[i],pos('Item Number',memo1.Lines[i])+12,pos('£',memo1.Lines[i])-3-pos('Item Number',memo1.Lines[i])-12-3);
        end;


end;

Open in new window

0
 
Ephraim WangoyaCommented:
Try like this
function GetItemNumber(const S: string): string;
const
  CItemNo = 'Item Number';
  CNumericSet: TSysCharSet = ['0','1','2','3','4','5','6','7','8','9'];
var
  Index: Integer;
begin
  Result := Trim(Copy(Trim(S), Length(CItemNo) + 1, 255));
  Index := 1;
  while Result[Index] in CNumericSet do
    Inc(Index);
  SetLength(Result, Index);
end;

procedure TForm13.Memo1Change(Sender: TObject);
var
  S: string;
  Memo: TMemo;
begin
  Memo := Sender as TMemo;

  ShowMessage(Memo.Lines[17]);

  DB4.TEXT:=(DateTimeToStr(Now)) ;
  S :=  Trim(Memo.Lines.Strings[3]);
  Delete(S, Length(S)- 13, 14);
  DBadd1.Text := Trim(S);

  DBname.Text := Memo.Lines.Strings[2];

  DBnote.Text := Memo.Lines.Strings[4];
  DBstatus.Text := Memo.Lines.Strings[5];
  DBadd2.Text := Memo.Lines.Strings[6];
  DB1.Text := Memo.Lines.Strings[7];
  DB2.Text := Memo.Lines.Strings[8];
  DB3.Text := Memo.Lines.Strings[9];
  DBhhb.Text := Memo.Lines.Strings[16];
  DBitem.Text := GetItemNumber(Trim(Memo.Lines.Strings[17]));
  DBPRICE.Text := Memo.Lines.Strings[22];
end;

Open in new window

0
 
boycoderAuthor Commented:
Excellent!!!!!


Thankyou also to both of you for your excellent help. If you dont mind ill give the points to jimmy this time? Saying it was posted first and worked. Again thanks to both of you for your expert help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 19
  • 7
  • 7
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now