?
Solved

quick question about format

Posted on 2011-05-06
10
Medium Priority
?
294 Views
Last Modified: 2012-08-14
Hi, when i put this code into my onform create , it compiles but doesnt start.
Can someone explain why it gives me an error, is my code ok?

i want it to, when form 13 loads, if BDadd1.text  is also inside the form35.special2.items.text .. show image. if not, dont show the image.

but if DBadd1.text is ' ' dont show image either..


   if
  form35.speciallist2.items.text=(DBadd1.text)
    then begin
    imagespecial.show;
 end;



Thanks
0
Comment
Question by:boycoder
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35706062
use this


if form35.speciallist2.items.IndexOf(Trim(DBadd1.text)) >=0 then
 begin
    imagespecial.show;
 end;
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35706067
When you start your application the listbox is empty (probably you fill it up later somewhere) so you need to test if it has any lines first.

Also the code should be:
   if
  form35.speciallist2.items.IndexOf(DBadd1.Text) = -1
    then begin
    imagespecial.show;
 end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 35706088
Oops:
   if
  form35.speciallist2.items.IndexOf(DBadd1.Text) > -1
    then begin
    imagespecial.show;
 end;

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 24

Expert Comment

by:jimyX
ID: 35706289
After rereading your question, it should be:
   if
  (form35.speciallist2.items.IndexOf(DBadd1.Text) > -1) and (DBadd1.text <> ' ')
    then begin
    imagespecial.show;
 end;

Open in new window


This code should be placed after ensuring speciallist2 has loading the data.
0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 35706298
Update code:
   if
  (form35.speciallist2.items.IndexOf(DBadd1.Text) > -1) and (DBadd1.text <> '')
    then begin
    imagespecial.show;
 end;

Open in new window

0
 

Author Closing Comment

by:boycoder
ID: 35706381
in the words of samuel jasckson. "nigga knoes his sh*t"

first class buddy, thanks to ewan also, cheers mate.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 35708079
i have noted that you do this :

if variable = (' test ')

why are you using the ( ) ?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 35708102
boycoder

it's a pity that jimyX isn't commenting on the bad parts in your code
you would learn a lot more if some experts were to go just a little bit further than just get the points with as little as possible comments
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35708332

Just to add to Geert_Gruwez comment

Let me give some little education right here
DBadd1.text is empty, IndexOf will return negative so ther is no need to test for DBadd1.text <> ' '

And here is another important lesson, when you exclude a value from a list search, you start by testing the value, not searching then testing
  if (DBadd1.text <> '') and form35.speciallist2.items.IndexOf(DBadd1.Text) >= 0) then
Once you start writing large programs, you will understand what I mean, but for now just take my word for it

Finally, don't compare your list search result to -1 (List.indexOf(S) = -1), Again this is one of those things that if you don't follow, you will learn the hard way in due time
 use List.IndexOf(S) >= 0

These are just some good practices you should get accustomed to
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35711509
Geert_Gruwez,
The author already mentioned why he puts () around some code in a previous question. Actually he was responding to you there. The pity is bringing this subject in every question.

ewangoya,
I am fully aware of that, but putting things to the way the author asked for is an advantage. The first solution was provided that will work and the second one is to fulfill what the author has requested, whether he is going to use it for the current scenario or just for future needs.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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