Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

problem with code ..

Posted on 2011-05-08
17
Medium Priority
?
318 Views
Last Modified: 2012-08-14
Hi, when i use this code it works with 1 TEDIT fine.. but not with a multiple ones
i need it so that, if it finds any of the text inside the edit boxes.. dont add and show the message.
When i test it with 1 edit, it worked, but if something was in the database as "DUML" it wouldnt add a word called DUMLB"

can we fix that too?

here is my code:

      if Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString=edit1.text + flatedit1.text + flatedit3.text +  flatedit5.text + flatedit7.text + flatedit9.text + flatedit10.text + flatedit11.text + flatedit8.text then
 begin
  Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
   exit;
  end
  else begin

REST OF THE CODE

also.. do i need the exit??


I think iam using + and it should be or? but it doesnt compile.

0
Comment
Question by:boycoder
  • 10
  • 7
17 Comments
 

Author Comment

by:boycoder
ID: 35715615
so it has find an exact match..

so if GFAAA-FFFGB-GGGGG is in the databse and if i try and add

DFAAA-FFFGB-GGGG let it add it.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35715708
There are many ways to do that, here is one which is by using Stringlist and add all your Editboxes and look for your data in there:
procedure TForm1.Button1Click(Sender: TObject);
var
  Str:TStringlist;
begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end;
  finally
    Str.Free;
  end;
end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 35715724
What you were trying to do actually is:
procedure TForm1.Button1Click(Sender: TObject);
var
  s:String;
begin
  s:=Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString;         // I used string variable instead of using the DB record every time
  if (s=edit1.text) or
     (s=flatedit1.text) or
     (s=flatedit3.text) or
     (s=flatedit5.text) or
     (s=flatedit7.text) or
     (s=flatedit9.text) or
     (s=flatedit10.text) or
     (s=flatedit11.text) or
     (s=flatedit8.text then
  begin
     Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',  MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
  end;
end;

Open in new window

0
Independent Software Vendors: 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!

 

Author Comment

by:boycoder
ID: 35715733
Thanks jim, but it must be a problem with my original code, as it doesnt seem to work. Here is the update button of the code.

what happens is, when i paste 10 serial numbers into memo1.text it auto puts them into the 10 edit boxes on MEMOCHANGE.

this is the in the button that adds the serials to the database but something isnt right.




procedure Tmassserials.goClick(Sender: TObject);

  var
  i : integer;

  Str:TStringlist;

begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;



   end else begin
  if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
 begin
  Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;

  end



  else begin

if
flatedit17.text=('')
then begin
 Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;

 end;
  if
sales.text=('')
then begin
 Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);

 end
 else begin
 if
 sheet.text=('Select a Sheet')
 then begin
  Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;


 end
else
 begin
                   if
                   memo1.text=('' )
                   then
 begin
  Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;



  end
  else begin




form1.adotable2.Insertrecord([nil,sales.text,edit1.Text,flatedit17.text,sheet.Text]);
form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit1.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit3.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit5.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit7.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit8.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit9.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit10.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit11.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;


    end;
  end;
    end;
     end;
     end;
  finally
    Str.Free;
  end;
 end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 35715737
I remember you mentioned before that you do not want to use queries DB, may I ask why? Because SQL is really going to help you a lot as it has a really very powerful functionality and can save a lot of your time (not necessarily in this current project but for future projects).
0
 

Author Comment

by:boycoder
ID: 35715743
ill try that second code jim
0
 

Author Comment

by:boycoder
ID: 35715749
ive never really got queries to work for me. lets give it a go as i cant get that code to fit in with my other code, must be a problem with my code.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35715776
Sorry took sometime to organize the code. Do you get error(s) or the code works but you do not get the expected result?

procedure Tmassserials.goClick(Sender: TObject);
var
  i : integer;
  Str:TStringlist;
begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end
    else
      begin
        if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
          begin
            Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
            MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
          end
        else
          begin
            if flatedit17.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
              end;
            if sales.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);
              end
            else
              begin
                if sheet.text='Select a Sheet' then
                  begin
                    Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
                    MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
                  end
                else
                  begin
                    if  memo1.text='' then
                      begin
                        Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
                        MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
                      end
                    else
                      begin
                        form1.adotable2.Insertrecord([nil,sales.text,edit1.Text,flatedit17.text,sheet.Text]);
                        form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit1.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit3.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit5.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit7.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit8.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit9.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit10.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit11.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;
                      end;
                  end;
              end;
          end;
      end;
  finally
    Str.Free;
  end;
end;

Open in new window

0
 

Author Comment

by:boycoder
ID: 35715804
I just dont get the expected result. That seems to work once jim, but after the error message,i cluck submit and it adds them.
then i click clear and try again and adds them as normal even if they are in the databse.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35715830
Still can't imagine what you are doing could you provide more details please?
Also you can replace the following steps:
form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

Open in new window


With just one line:
form1.adotable2.Insertrecord([null,sales.text,flatedit18.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);
0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 35715845
Let's try this way please:
procedure Tmassserials.goClick(Sender: TObject);
var
  i : integer;
  Str:TStringlist;
begin
    Str:=TStringlist.Create;
    Str.Add(uppercase(edit1.text));
    Str.Add(uppercase(flatedit1.text));
    Str.Add(uppercase(flatedit3.text));
    Str.Add(uppercase(flatedit5.text));
    Str.Add(uppercase(flatedit7.text));
    Str.Add(uppercase(flatedit9.text));
    Str.Add(uppercase(flatedit10.text));
    Str.Add(uppercase(flatedit11.text));
    Str.Add(uppercase(flatedit8.text));
    if Str.IndexOf(uppercase(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString)) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end
    else
      begin
        if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
          begin
            Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
            MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
          end
        else
          begin
            if flatedit17.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
              end;
            if sales.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);
              end
            else
              begin
                if sheet.text='Select a Sheet' then
                  begin
                    Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
                    MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
                  end
                else
                  begin
                    if  memo1.text='' then
                      begin
                        Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
                        MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
                      end
                    else
                      begin
                        form1.adotable2.Insertrecord([null,sales.text,edit1.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit1.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit3.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit5.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit7.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit8.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit9.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit10.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit11.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit18.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);
                      end;
                  end;
              end;
          end;
      end;
    Str.Free;
end;

Open in new window

0
 

Author Comment

by:boycoder
ID: 35715946
that seems to work jimmy thanks mate, but if i close down the form, then reopen it again and do it then, it adds them. is there a way to free it or something so when i open the form again, it allows the protection we have added ?

thanks again

oh by the way, i had to change to first null to Nil as it would let me write into the database but still works.
0
 

Author Comment

by:boycoder
ID: 35715978
um sorry it didnt work.. it was another error.. is there a simple way to di this like...


if memo1.text matches anything isside adotable.byname'Serial numbers' show error message. ?
0
 

Author Comment

by:boycoder
ID: 35716008
its ok jimmy mate, it isnt really that important , the chances of me adding the same serial twice is remote. unless we can put that code somewhere else..

can we have it on form 1, if anything is added to the database run this check ?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35716055
It will be much clearer if you give an example of what happens and what you want it to be.
Can use the TeamViewer to give me limited access to your PC?
0
 

Author Comment

by:boycoder
ID: 35716599
Hi jim, its all working now, sorry about the delay i had to nip out. cheers mate thanks very much!!
0
 

Author Closing Comment

by:boycoder
ID: 35716601
A
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question