Solved

String Comparison TEdit vs ADOConnection

Posted on 2004-08-11
6
181 Views
Last Modified: 2010-04-05
Hi,

I have to following problem. I have an TEdit password field which needs to check the value from the TEdit field (pwField) with the result from the query. If the two values are exactly the same, go is set to True. The problem is this: the "If pwd = realPwd then" statement always returns False for some reason, even when the values are the same. Can anybody help me out with this?

The Code Snippet:
===========================================
procedure TAfmeldStoring.HelpDeskAfmeldenClick(Sender: TObject);
var
  go : boolean;
  realPwd, pwd: string;
begin
    go := False;
    ADOConnectionA.Close;
    ADOQueryA := TADOQuery.Create(nil);
    ADOQueryA.Connection := ADOConnectionA;
    ADOQueryA.SQL.Text := 'Select password from LUpasswords where application = '+CHR(39)+'MyApp'+CHR(39);
    ADOQueryA.Open;
    pwd := pwField.Text;
    If ADOQueryA.RecordCount<>0 then begin
      realPwd := AdoQueryA.Fields[0].Value;
    end;
    ADOQueryA.Close;
    ADOConnectionA.Close;

    if pwd = realPwd then
      go := True;
end;
0
Comment
Question by:jornv
6 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 11771054
Hi
1. go might not be set because it is local variable and it is not used anywhere.
2. Don't use RecordCount rather Eof and Bof
0
 

Author Comment

by:jornv
ID: 11771066
No, this part:
======
if pwd = realPwd then
      go := True;

will always return false, if the go is locally declared or not that aint the problem, be cause it doesnt even reaches that since it returns false.
0
 
LVL 17

Expert Comment

by:mokule
ID: 11771159
It is a problem
Look at the code below

procedure TForm1.Button1Click(Sender: TObject);
var
  go: boolean;
  s1,s2: string;
begin
  go := False;    // there is no blue dot on the left margin - it is not executed
  s1 := 'x';
  s2 := 'x';
  if s1 = s2 then
    go := True;    // there is no blue dot on the left margin - it is not executed
end;
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Accepted Solution

by:
DarkCore_ earned 50 total points
ID: 11771227
try  go := pwd = realPwd

Edu
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11771378
change the query to :

Select UPPER(password) from LUpasswords

and then the check should be

if UpperCase(pwd) = UpperCase(realPwd) then
      go := True;
0
 

Author Comment

by:jornv
ID: 11771412
Thanks DarkCore_, this is what I needed, it works case sensitive and I dont need to declare a global variable
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now